Jump to content

Finish a dll


Recommended Posts

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??

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy