The problem is as follows:

The task is to start the DLL function on the command line, when calling, the user must enter the size of the array, which is filled with random values, the number of threads and the priority of threads. At startup, a window appears but nothing can be entered.

The DLL itself is working, used for static and dynamic connections, but you need to run the function through the console.

Also, one person said that the problem is that I am not an absolute administrator.

extern "C" __declspec(dllexport) void lab4() { AllocConsole(); freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); GetModuleFileName(NULL, (LPTSTR)module, MAXMODULE); cout << "\n\nThis function was called from " << module << endl << endl; srand(time(NULL)); int arrSize; int numOfThreads; int numOfPriority; GetModuleFileName(NULL, (LPTSTR)module, MAXMODULE); HANDLE hMutex = CreateMutex(NULL, FALSE, NULL); if (hMutex == NULL) { printf("CreateMutex error: %d\n", GetLastError()); } DWORD thread_priority; DWORD thread_ID; cout << "Array size: "; cin >> arrSize; cout << "Num of Threads: "; cin >> numOfThreads; cout << "NumOfPriority (0-IDLE; 1-LOWEST; 2-NORMAL; 3-HIGHEST; 4-TIME_CRITICAL):"; cin >> numOfPriority; if (numOfPriority == 0)thread_priority = THREAD_PRIORITY_IDLE; else if (numOfPriority == 1)thread_priority = THREAD_PRIORITY_LOWEST; else if (numOfPriority == 2)thread_priority = THREAD_PRIORITY_NORMAL; else if (numOfPriority == 3)thread_priority = THREAD_PRIORITY_HIGHEST; else if (numOfPriority == 4)thread_priority = THREAD_PRIORITY_TIME_CRITICAL; HANDLE *hThr = new HANDLE[numOfThreads]; threadParam *MyParam = new threadParam[numOfThreads]; int *MyArray = new int[arrSize]; for (int i = 0; i < arrSize; i++)MyArray[i] = 1 + rand() % 100; int step = arrSize / numOfThreads; for (int i = 0; i < numOfThreads; i++) { MyParam[i].ptr = MyArray; MyParam[i].indexStart = i * step; MyParam[i].indexEnd = i * step + step - 1; MyParam[i].length = arrSize; if (i == numOfThreads - 1)MyParam[i].indexEnd = arrSize - 1; } for (int i = 0; i < numOfThreads; i++) { WaitForSingleObject(hMutex, INFINITE); hThr[i] = CreateThread(NULL, 0, SortArray, (PVOID)&MyParam[i], CREATE_SUSPENDED, &thread_ID); SetThreadPriority(hThr[i], thread_priority); ResumeThread(hThr[i]); ReleaseMutex(hMutex); Sleep(100); } 

dll startup screenshot

  • freopen_s((FILE**)stdout, ... - what is it ??? If we really follow this path, then probably there should be freopen_s(&stdout, ... ? I suspect that you first wrote freopen_s(stdout, ... , the compiler poked your nose at the type mismatch error, and you decided, without thinking twice, just shut the throat with it (FILE **) . It turned out nonsense. - AnT
  • @AnT well, is that all? - apolloisggg
  • stdin won't redirect itself - VTT

0