123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #define _CRT_SECURE_NO_WARNINGS
- #include <windows.h>
- #include <stdio.h>
- #include <malloc.h>
- #include <string.h>
- #include "../structs.h"
- BOOL WINAPI DllMain(HINSTANCE hlnstDll, DWORD dwReason, LPVOID IpReserved)
- {
- BOOL bAllWentWell = TRUE;
- switch (dwReason)
- {
- case DLL_PROCESS_ATTACH:
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- case DLL_PROCESS_DETACH:
- break;
- }
- if (bAllWentWell)
- return TRUE;
- else
- return FALSE;
- }
- //extern "C" __declspec(dllimport) int MyFunc(const wchar_t* str);
- //int MyFunc(const wchar_t* str) {
- // MessageBox(NULL, str, L"ß äà", MB_OK);
- // return 0;
- //}
- int Convert_sub(char* sub) {
- int result = 0;
- int ymnoz = 1;
- for (size_t i = 0; i < strlen(sub); i++)
- {
- result *= ymnoz;
- result += sub[i] - '0';
- ymnoz *= 10;
- }
- return result;
- }
- extern "C" __declspec(dllimport) ResultUserAndCount GetFirstAndCounter(FILE* file_read);
- ResultUserAndCount GetFirstAndCounter(FILE* file_read) {
- ResultUserAndCount result = { NULL, 0 };
- User* list_user = (User*)malloc(sizeof(User) * 200);
- char* buffer = (char*)malloc(sizeof(char) * 100);
- int index_start = 0;
- int index_list = 0;
- int count_user = 0;
- int count_sub_char = 0;
- while (fscanf(file_read, "%s", buffer) == 1) {
- for (size_t i = 0; i < strlen(buffer); i++)
- {
- if (buffer[i] != '\r' && buffer[i] != '\n' && buffer[i] != '\"') {
- if (buffer[i] == ';')
- {
- char* sub = (char*)malloc(sizeof(char) * 100);
- int index_sub = 0;
- for (size_t j = index_start + 1; j < i; j++)
- {
- sub[index_sub] = buffer[j];
- index_sub++;
- }
- sub[index_sub] = '\0';
- index_start = i;
- switch (count_sub_char)
- {
- case 0:
- list_user[index_list].last_name = sub;
- break;
- case 1:
- list_user[index_list].first_name = sub;
- break;
- case 2:
- list_user[index_list].patrinymic = sub;
- break;
- default:
- break;
- }
- count_sub_char++;
-
- }
- }
- else if (buffer[i] == '\"' && count_sub_char != 0) {
- char* sub = (char*)malloc(sizeof(char) * 100);
- int index_sub = 0;
- for (size_t j = index_start + 1; j < i; j++)
- {
- sub[index_sub] = buffer[j];
- index_sub++;
- }
- sub[index_sub] = '\0';
- list_user[index_list].age = Convert_sub(sub);
- count_sub_char = 0;
- index_start = 0;
- index_list++;
- count_user++;
- }
- }
- }
- result.count_users = count_user;
- result.user = list_user[0];
- return result;
- }
|