Hi all,
My code is somthing like the following:
Is this the correct way to shutdown a thread on calling FreeLibrary() from the app that loaded the DLL?Code://global BOOL terminated; BOOL APIENTRY DllMain(HANDLE hinst, DWORD reason, LPVOID lpReserved) { if (reason == DLL_PROCESS_ATTACH) { //starting DisableThreadLibraryCalls((HINSTANCE)hinst); terminated = FALSE; thread_handle = CreateThread(NULL, 0, run_thread, 0, CREATE_SUSPENDED, &thread_id); SetThreadPriority(thread_handle, THREAD_PRIORITY_HIGHEST); ResumeThread(thread_handle); } if (reason == DLL_PROCESS_DETACH) { if (lpReserved != NULL) log_log(LOG_CRITICAL, "DllMain", "plugin exception error, terminated"); //ending terminated = TRUE; } return 1; } //--------------------------------------------------------------------------- DWORD __stdcall run_thread(LPVOID lparam) { //setup the log log_start("thingie"); //init timers timer_calibrate(); //start main thread loop while (terminated == FALSE) { //do stuff here timer_lazysleep(0.020); } //stop logging log_end(); //done FreeLibraryAndExitThread((HMODULE)lparam, 0); return 0; }
Im guessing its not, due to using the "terminated" global var, but i cant think of how it should be done properly.
Thanks.



LinkBack URL
About LinkBacks



.