How do I get a DLL to close itself when it has finished its task

Hi ,
I am trying to write an app that calls a DLL (it is called from a unit that has no form). The DLL goes off and does some stuff, then some time later it informs the main program's calling unit (via a Callback routine) that it has finished (with the string "DLL finished").

Then I wish to issue a "Freelibrary" command to release the DLL.

Now, I can close the DLL at any time if the Freelibrary command is coded as part of a button click event on my main form, but I would like the closing of the DLL to be done automatically when that string is sent via the Callback routine.

But when I try this the program fails with

Project xxxxx faulted with message:"access violation at 0x00ef4e63 read address 0x00ef4e63. Process stopped"

I have put the Freelibrary command in the Callback routine itself (in the calling unit), having of course tested that the string contains "DLL finished". I am guessing my problem occurs because I am issuing the Freelibrary command from within the Callback routine, while the DLL is still using that Callback routine.

I guess my question is, how can a DLL cause or request itself to be closed ? Many thanks,

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!