Dll Detach function?
BlitzMax Forums/BlitzMax Programming/Dll Detach function?
| ||
| Is there a way to declare the function that is called when dlls are detached? I would like to add a few commands in this. |
| ||
This ought to work:Function DllMain(hinstDLL:Byte Ptr,fdwReason:Int,lpvReserved:Byte Ptr)"win32"
Select fdwReason
Case 0 ' DLL_PROCESS_DETACH
Notify("DETACH!")
Case 1 ' DLL_PROCESS_ATTACH
Notify("ATTACH!")
Case 2 ' DLL_THREAD_ATTACH
Case 3 ' DLL_THREAD_DETACH
End Select
Return True 'Must return true to tell LoadLibrary that everything is ok
End Function |
| ||
| thanks |
| ||
Looking at Appstub.win32.c
BOOL WINAPI DllMain( HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved ){
if( fdwReason!=DLL_PROCESS_ATTACH ) return 1;
bbLibStartup();
__bb_appstub_appstub();
return 1;
}
No However theoritically OnEnd registered functions should fire upon cleanup of the C Runtime Library. Doug |
| ||
| Fredborg, I tried your function, adding a notification whenever it was called, but it does not seem to ever be called. I tried exporting and not exporting the function. |
| ||
| @Josh Jermeys code wont work as the routine I posted is linked in by MAX as the DLL entry point and you cant override unless you change options on LD. Also if you do what he did the BMAX runtime wont be intialized correctly. try OnEnd, if that doesnt work I can help guide you through a custom APPStub similar to what happens Brucy did for WxWidgets. Doug |
| ||
| Right, I had that lying around from a previous version of BMax, before it had any internal handling of dll attaching, detaching etc. Budman is probably right, but I have no time to test it. |
| ||
| @fredborg thats right I remeber that myself now mention it. You had manaully link in the dll stub before Mark added DLL support to Appstub. Your dating yourself as a BMax user :) Doug |