Re: Calling FreeLibrary in destructor
"Rastko Soskic" <rastkososkic@yahoo.com> wrote in message
news:%23eZbzpdQIHA.3516@TK2MSFTNGP02.phx.gbl...
Hi everyone, here is an issue.
Program is simple so I will briefly describe issue because somebody will
recognize problem as "regular one" for beginners :)
If it would be neccessary will include code also.
On creation of window (wm_create) i am instantiating some object (there is
pointer globally declared).
On destruction (wm_destroy) i am deleting that object.
In constructor there is call to LoadLibrary (object needs some functions
from dll) and it works perfectly always.
However in destructor is called FreeLibrary. There problem arises. If
FreeLibrary is called in destructor
Access violation exception is thrown. In addition if I Load and Free
library
immediately in constructor, there is no access violation.
What is the call stack of the access violation? Probably not the
destructor. If it is, then you must have corrupted the library internal
state so much that its DllMain fails when called with the *_DETACH argument.
What I am doing wrong? I've read something about implicit and explicit
binding (and that some dlls are not proper for explicit binding) but that
haven't explained why FreeLibrary does not
imply error when called immediately after LoadLibrary but implies error if
called in destructor.
Thanks in advance.