Shoutbox

Unloading a dll - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Unloading a dll (/showthread.php?tid=62373)

Unloading a dll by cooldude_i06 on 07-02-2006 at 11:55 PM

I'm using a custom ActiveX Dll. For some reason the dll won't unload until WLM exists, even if the script is stopped. This happens even if all I do is create an activexobject and not use it further at all. Is there anything special I need to do to free up the dll.

Btw, The Class_Terminate event does fire, but dll still remains in memory.
The delete operator, or setting ActiveXObject to null does not help.

This problem makes it hard for any script that uses ActiveX dll to be removed. You must stop the script, restart WLM, and then delete the script.

Thanks
CD


RE: Unloading a dll by Mike on 07-03-2006 at 12:03 AM

I had asked the same thing on the beta testing forums a while ago.
My DLL also wouldn't unload.

It seems that there is no way of unloading your ActiveX DLL... :(


RE: Unloading a dll by deAd on 07-03-2006 at 12:20 AM

did you try:

code:
//create activexobject
var MyVar = new ActiveXObject(...);
//delete the object
delete MyVar;


RE: Unloading a dll by aNILEator on 07-03-2006 at 12:36 AM

hey deAd have you given that to alex, because itunes+ still has problems unloading that .dll :(


RE: Unloading a dll by deAd on 07-03-2006 at 12:50 AM

No, I didn't know that alex was having problems. I'll talk to him. Also, I haven't tested that, not sure if it works completely...


RE: Unloading a dll by cooldude_i06 on 07-03-2006 at 01:35 AM

quote:
Originally posted by deAd
did you try:
code:
//create activexobject
var MyVar = new ActiveXObject(...);
//delete the object
delete MyVar;




the delete operator doesnot help
RE: Unloading a dll by deAd on 07-03-2006 at 01:39 AM

oh ok, as i said, didn't know for sure if that works :$


RE: Unloading a dll by matty on 07-03-2006 at 02:39 AM

Well I just realized the way of doing it (I actually forgot I did this with coding Plugins I was coding in VB so I could overwrite them.)

@echo off
reloadplugins.exe
regsvr32 /u /s "C:\program files\messengerplus! 3\plugins\screenshotsender.dll"
reloadplugins.exe
del /q "C:\program files\messengerplus! 3\plugins\screenshotsender.dll"
Echo Compile the dll now.
pause
regsvr32 /s "C:\program files\messengerplus! 3\plugins\screenshotsender.dll"
reloadplugins.exe

So basically I reloaded and unregistered the dll so that it could be deleted. Something like this would need to be done so that the DLL could be deleted.


RE: Unloading a dll by cooldude_i06 on 07-03-2006 at 08:38 AM

quote:
Originally posted by Matty
Well I just realized the way of doing it (I actually forgot I did this with coding Plugins I was coding in VB so I could overwrite them.)

@echo off
reloadplugins.exe
regsvr32 /u /s "C:\program files\messengerplus! 3\plugins\screenshotsender.dll"
reloadplugins.exe
del /q "C:\program files\messengerplus! 3\plugins\screenshotsender.dll"
Echo Compile the dll now.
pause
regsvr32 /s "C:\program files\messengerplus! 3\plugins\screenshotsender.dll"
reloadplugins.exe

So basically I reloaded and unregistered the dll so that it could be deleted. Something like this would need to be done so that the DLL could be deleted.

I discovered something using your method...

First I stopped the script, unregistered the dll, and deleted the dll - it worked fine.
Next time I stopped the script, unregistered the dll, and tried removing the dll from Plus Preferences - it did not work.
Then I stopped the script, left the dll registered, and deleted it - it worked.
Then I stopped the script, left the dll registered and tried deleting it from Plus Preferences - it did not work.

Finally, I stopped the script, close the WLM main window, then tried removing the script from Plus Preferences - it worked.

Thus I discovered that the dll is only locked until the WLM window is open. You can even leave WLM running, just close the main window, and the dll becomes unlocked. Unfortunately this means that unregistering a dll won't help unload a dll.

EDIT:

Here's the method I'm going to use.

Script contains the dll, but does not register it in ScriptInfo.xml.

When script is run it copies the dll to a different directory. Before doing this it checks if the dll already exists in new directory or not. It also registers the dll after copying it.

Script now uses this dll copied to a different directory. Now that this dll is in a different directory, when the script is deleted the dll in its directory won't be the one that is locked, and won't deny access.

This is the only method that I can think of to solve this problem. Hopefully as more people use dll's they'll come up with a better solution.
RE: Unloading a dll by felipEx on 07-03-2006 at 09:53 AM

Interop.FreeDll("your_dll_libray.dll");
FreeDll("your_dll_libray.dll");

*-)


RE: Unloading a dll by cooldude_i06 on 07-03-2006 at 07:36 PM

quote:
Originally posted by afelipE_scripts
Interop.FreeDll("your_dll_libray.dll");
FreeDll("your_dll_libray.dll");

*-)

lol, we wouldn't have missed that if it worked.
Interop.FreeDll only works for Dlls that were called by Interop.Call, because I think then WLM does not take control of it. Where as when you use ActiveXObject, WLM takes control of it and wont release it until its closed. (I think)