Dll Detach function?

BlitzMax Forums/BlitzMax Programming/Dll Detach function?

JoshK(Posted 2008) [#1]
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.


fredborg(Posted 2008) [#2]
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



JoshK(Posted 2008) [#3]
thanks


DStastny(Posted 2008) [#4]
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


JoshK(Posted 2008) [#5]
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.


DStastny(Posted 2008) [#6]
@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


fredborg(Posted 2008) [#7]
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.


DStastny(Posted 2008) [#8]
@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