开发者

How to delete openssl dlls before closing the application

I made a simple tool (LogAndMailApplication) that sends logs to my gmail account, for this I used the Indy component TIdSSLIOHandlerSocketOpenSSL. To work it needs ssleay32.dll and libeay32.dll.

So at application start I extract from exe resources the 2 dll and I copy them to the application folder.

All the indy compoennts are in a datamodule I destroy before closing the application.

After destroying the datamodule I try to delete the dlls but I cannot.

I just used DeleteFile, but that worked great for all the other files I delete on application exit (incluging an ini file).

I trie开发者_Python百科d to make a simple exe that just deletes the 2 dll and it works. So the problem is that the 2 dll are somehow locked until the LogAndMailApplication is not closed, how to solve the problem?


Indy dynamically loads the OpenSSL DLLs at runtime, and then by default does not unload them until app shutdown. If you want to unload the DLLs sooner, you need to call IdSSLOpenSSL.UnLoadOpenSSLLibrary() directly. This will unload the DLLs and clean up all references and allocated objects related to them.


You can do the following: at the very end of your code use

FreeLibrary(GetModuleHandle('ssleay32.dll')); FreeLibrary(GetModuleHandle('libeay32.dll')); DeleteFile(PathToDLL1); DeleteFile(PathToDLL2);

This should work.

Alternatively you can get rid of OpenSSL and use SSL components from our SecureBlackbox.


Alternatively you can delete the DLL's in the finalization section of the data module unit...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜