Subject: | dll not unloaded if the first new fails |
I have a problem that I think can be solved easily. Here's the pseudo code for my application.
1. Use new Win32::API to determine if A.DLL exports foo()
2. If it does, then "my product is enabled", otherwise replace A.DLL with Aprime.DLL
3. If the replace fails, then show which processes have A.DLL open
Even if no other process loaded A.DLL, my process does. But step 1 fails to return a handle because the existing version of A.DLL doesn't have foo. And because step 1 doesn't return a handle I cannot unload A.DLL.
I propose the following:
If LoadLibrary() succeeds but the subsequent GetProcAddress() calls fail, then FreeLibrary() if Procedures{$dll} isn't defined or equals zero.
I've attached the diff output.
$ diff APInew.pm API.pm
65a66
> $Libraries{$dll} = $hdll;
77,80c78
< unless ($proc) {
< Win32::API::FreeLibrary($hdll) unless $Procedures{$dll};
< return undef;
< }
---
> return undef unless $proc;
111d108
< Win32::API::FreeLibrary($hdll) unless $Procedures{$dll};