_Carlos_ Posted January 27, 2009 Report Share Posted January 27, 2009 Hello people,I'm new programming dlls in c++, and I have one question that I don´t understand.I have created a dll, that it's load in a thread, and then the thread finishes, I dont know how finish the dll.I have this code in my main method:BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ){ switch(ul_reason_for_call) { case DLL_PROCESS_ATTACH: g_hModule = hModule; Init(); return TRUE; case DLL_PROCESS_DETACH: Cleanup(); return TRUE; }I don´t understand when the program calls DllMain in the case DLL_PROCESS_DETACH.Please, anybody knows?? Quote Link to comment Share on other sites More sharing options...
ɹəuəllıʍ ʇɐb Posted January 28, 2009 Report Share Posted January 28, 2009 Welcome to the Windows Forum.What exactly do you mean "finish the dll" - release the loaded dll module? Is it not automatically released? Quote Link to comment Share on other sites More sharing options...
_Carlos_ Posted January 28, 2009 Author Report Share Posted January 28, 2009 Welcome to the Windows Forum.What exactly do you mean "finish the dll" - release the loaded dll module? Is it not automatically released?Sorry, I explain me not very well.Yes, I mean that release the loaded dll module.I have a thread that loads the dll, and in it, I install a hook in the beginning of the dll. When I do:Thread.currentThread().stop();The program in java finishes, but the dll is running during a lot of time.To finish the dll, I need to call maindll in the case PROCESS_DETACH:case DLL_PROCESS_DETACH: Cleanup(); return TRUE;because in Cleanup:static void Cleanup(){ if( hkb != NULL ) UnhookWindowsHookEx( hkb ); hkb = NULL;}Is where I Unhook, and the dll stops running.Then, I don´t know when DLL_PROCESS_DETACH case occurs, somethig like unload, or I don´t know.Thanks :) Quote Link to comment Share on other sites More sharing options...
_Carlos_ Posted January 28, 2009 Author Report Share Posted January 28, 2009 Hello people!!I have resolved it!!The problem was that when I stop the thread it calls to the entry-point function with the case DLL_THREAD_DETACH, instead of with the case DLL_PROCESS_DETACH.Thanks for your help :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.