Click to See Complete Forum and Search --> : Calling End From a DLL
Goldie
May 16th, 2001, 09:32 AM
I am trying to build an series of applications. These applications are standard .exe's.Each application accesses a standard set of fuctionality inside an Activex DLL. This Dll also contains a VB form which is positioned along the bottom of the screen, above which, the forms for each of the .exe's are positioned. The form inside the DLL has an exit button it.
Is there anyway to make the application exit if this button is pressed. I have tried putting a call to "end" on the button, but I am not able to use this inside the DLL.
regards
goldie
Cimperiali
May 16th, 2001, 09:41 AM
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.
Clearcode
May 16th, 2001, 10:51 AM
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
Cimperiali
May 17th, 2001, 02:38 AM
"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.
Clearcode
May 17th, 2001, 03:54 AM
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
Cimperiali
May 17th, 2001, 04:49 AM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.