CodeDLL.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <malloc.h>
  5. #include <string.h>
  6. #include "../structs.h"
  7. BOOL WINAPI DllMain(HINSTANCE hlnstDll, DWORD dwReason, LPVOID IpReserved)
  8. {
  9. BOOL bAllWentWell = TRUE;
  10. switch (dwReason)
  11. {
  12. case DLL_PROCESS_ATTACH:
  13. break;
  14. case DLL_THREAD_ATTACH:
  15. break;
  16. case DLL_THREAD_DETACH:
  17. break;
  18. case DLL_PROCESS_DETACH:
  19. break;
  20. }
  21. if (bAllWentWell)
  22. return TRUE;
  23. else
  24. return FALSE;
  25. }
  26. //extern "C" __declspec(dllimport) int MyFunc(const wchar_t* str);
  27. //int MyFunc(const wchar_t* str) {
  28. // MessageBox(NULL, str, L"ß äà", MB_OK);
  29. // return 0;
  30. //}
  31. int Convert_sub(char* sub) {
  32. int result = 0;
  33. int ymnoz = 1;
  34. for (size_t i = 0; i < strlen(sub); i++)
  35. {
  36. result *= ymnoz;
  37. result += sub[i] - '0';
  38. ymnoz *= 10;
  39. }
  40. return result;
  41. }
  42. extern "C" __declspec(dllimport) ResultUserAndCount GetFirstAndCounter(FILE* file_read);
  43. ResultUserAndCount GetFirstAndCounter(FILE* file_read) {
  44. ResultUserAndCount result = { NULL, 0 };
  45. User* list_user = (User*)malloc(sizeof(User) * 200);
  46. char* buffer = (char*)malloc(sizeof(char) * 100);
  47. int index_start = 0;
  48. int index_list = 0;
  49. int count_user = 0;
  50. int count_sub_char = 0;
  51. while (fscanf(file_read, "%s", buffer) == 1) {
  52. for (size_t i = 0; i < strlen(buffer); i++)
  53. {
  54. if (buffer[i] != '\r' && buffer[i] != '\n' && buffer[i] != '\"') {
  55. if (buffer[i] == ';')
  56. {
  57. char* sub = (char*)malloc(sizeof(char) * 100);
  58. int index_sub = 0;
  59. for (size_t j = index_start + 1; j < i; j++)
  60. {
  61. sub[index_sub] = buffer[j];
  62. index_sub++;
  63. }
  64. sub[index_sub] = '\0';
  65. index_start = i;
  66. switch (count_sub_char)
  67. {
  68. case 0:
  69. list_user[index_list].last_name = sub;
  70. break;
  71. case 1:
  72. list_user[index_list].first_name = sub;
  73. break;
  74. case 2:
  75. list_user[index_list].patrinymic = sub;
  76. break;
  77. default:
  78. break;
  79. }
  80. count_sub_char++;
  81. }
  82. }
  83. else if (buffer[i] == '\"' && count_sub_char != 0) {
  84. char* sub = (char*)malloc(sizeof(char) * 100);
  85. int index_sub = 0;
  86. for (size_t j = index_start + 1; j < i; j++)
  87. {
  88. sub[index_sub] = buffer[j];
  89. index_sub++;
  90. }
  91. sub[index_sub] = '\0';
  92. list_user[index_list].age = Convert_sub(sub);
  93. count_sub_char = 0;
  94. index_start = 0;
  95. index_list++;
  96. count_user++;
  97. }
  98. }
  99. }
  100. result.count_users = count_user;
  101. result.user = list_user[0];
  102. return result;
  103. }