DLLCanUnloadNow Question
Paul Chitescu
paulc at voip.null.ro
Fri Oct 7 04:10:41 CDT 2011
On Friday 07 October 2011 11:50:17 am Alistair Leslie-Hughes wrote:
> Hi,
>
> The Following sample code causes a crash under WINE, but not in windows.
>
> IUnknown *p
>
> LoadLibrary("mscoree.dll")
> GetProcAddress("CreateDebuggingInterfaceFromVersion")
> CreateDebuggingInterfaceFromVersion(..., (void**)&p) <-- Com Reference
>
> FreeLibrary("mscoree.dll")
>
> p->QueryInterface(....); <-- Cause Crash under WINE.
>
>
> The DLL shouldn't be unloaded since mscoree.DLLCanUnloadNow() return
> S_FALSE;
>
> Is this a bug with the unloading of DLL's? Is there way to stop the
> unloading of a DLL?
>
> I know the logic isn't the best, but I'm seeing this type of behavior in an
> application.
>
> Best Regards
> Alistair Leslie-Hughes
Hi!
It doesn't seem your test is correct. You are not supposed to use LoadLibrary
directly but use COM methods that will call FreeLibrary internally when
DLLCanUnloadNow returns true.
The fact it doesn't crash on Windows is probably caused by mscoree.dll being
kept loaded by some other components. I don't know, maybe on Windows mscoree
is never unloaded - this can be verified easily.
If there are actually programs that crash that way because they depend on the
Windows behavior we can work around by making internally a LoadLibrary call
when the first object is created and a FreeLibrary call after the last object
is destroyed.
Paul
More information about the wine-devel
mailing list