Re: Calling End From a DLL
As far as I know (beware: I know a little, and may be wrong!):
Dll is a component instanciated by your exe. That means exe should close dll and then exit, not the contrary. But you can make it raising an event from dll to exe, where you can code the closing of dll (remember to unload its form and set it to nothing!) and then of the exe. Matter is: you may need to set the component to = noting only from last closing exe, so maybe you will have to count exe using the dll from inside dll and pass this value to each exe...
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
Re: Calling End From a DLL
Firstly you should never use the End keyword.
If you raise an event from your DLL to each calling app they shouldn't be able to set object = nothing
because the event would have nowhere to return to.
Instead, register a windows message and post it asynchronously to the apps that have a reference to your dll. On recieving this message, the app should set object = nothing
which will decement the reference count for that dll.
When the reference count reaches zero it will automatically be unloaded by Windows.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Re: Calling End From a DLL
"register a windows message and post it asynchronously to the apps that have a reference to your dll. "...
As I am not sure about how to do it, may I have a sample code?
Thanks,
Cesare Imperiali
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
Re: Calling End From a DLL
What I would do is have the message ID bit in a common procedure in all your projects something like:
private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (byval lpString as string) as Long
public Function DLLUnloadWindowMessage() as Long
If mMessage = 0 then
mMessage = RegisterWindowMessage("UNLOAD_DLL")
End If
DLLUnloadWindowMessage= mMessage
End property
Then subclass the WNDPROC of the forms which call the DLL (do a search for "WNDPROC" to get an example).
public Function VB_WindowProc(byval hwnd as Long, byval wMsg as Long, byval wParam as Long, byval lParam as Long) as Long
If wMsg = DLLUnloadWindowMessage() then
'\\ Drop reference to the dll...
set objrefvar = nothing
End If
End Function
and in the dll, to send a message:
private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, byval lParam as Long) as Long
HWND_BROADCAST = &HFFFF&
public Sub EndDll()
lRet = SendMessageLong(HWND_BROADCAST, DLLUnloadWindowMessage(), 0,0)
End Sub
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Re: Calling End From a DLL
Thanks. I will rate you as soon as possible
(out of vote for today...)
Cesare Imperiali
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.