I have DLL which connects to EXE and works there. Exe is not my program. My DLL just create VCL child form.Is the way to unload my dll from EXE after, for example, user closed my child form?
I tried to unload my own DLL by creating thread and executing FreeLibraryAndExitThread
but got Access Violation.
There I'm trying to unload dll after DLL_PROCESS_ATTACH
:
#include <vcl.h>
#include <windows.h>
#include <process.h>
#include <vector>
DWORD WINAPI Eject(LPVOID Param) {
ShowMessage("EJECT");
FreeLibraryAndExitThread(HINSTANCE(Param), 0);
return 1;
}
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
switch(reason) {
case DLL_PROCESS_ATTACH: {
ShowMessage("ATTACH");
CreateThread(NULL,NULL,Eject,hinst,NULL,NULL);
break;
}
}
return 1;
}
After ShowMessage("EJECT");
my App is crashing.
Is the way to unload dll from itself?