CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2001
    Location
    Milton Keynes United Kingdom
    Posts
    3

    Calling End From a DLL

    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


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured