Problem killing a thread
Hello,
I am creating a DLL that creates another thread and does its work.
When I load the library, it calls CreateThread which spawns another
thread. I am having a hard time terminating the thread. For some
reason, when it runs DLL_PROCESS_DETACH, and executes TerminateThread,
the thread does not terminate.
Would anyone know what I could be doing wrong?
It seems fairly simple. Thanks
I have the following code:
////////////////////////////////////////////////////////////////
long WINAPI Temp(long lParam) {
int result;
for(;;) {
// my new thread
}
return 0;
}
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
LPVOID lpReserved ) {
HANDLE hThread = new HANDLE();
DWORD dwID;
switch( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH:
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Temp, NULL,
0, &dwID);
break;
case DLL_PROCESS_DETACH:
TerminateThread(hThread, 0);
CloseHandle(hThread);
delete(hThread);
MessageBox(NULL, "Detaching Process", "Note", MB_OK);
break;
default:
break;
}
return TRUE;
}