Re: Module handle of a given object instance
On Thu, 17 Jul 2008 16:58:04 +0200, "Giovanni Dicanio"
<gdicanio@_NOSPAM_email_DOT_it> wrote:
"Andy pandy 2" <devteam@transvalor.com> ha scritto nel messaggio
news:b8077a23-c297-4d51-be53-d927b9aaaa33@z66g2000hsc.googlegroups.com...
Does anybody know how to obtain a handle to the module in which a
given object instance was created (allocated) ?
For example, in DLL2.dll, I allocate an object
MyDerivedObject* pInstance = new MyDerivedObject()
MyDerivedObject derives from MyObject, a base class implmented in
another dll, DLL1.dll .
Then I use base class methods located in DLL1.dll
pInstance->ABaseClassMethod()
Witihin MyObject::ABaseClassMethod(), I would like to know where
"this" was allocated, i.e. get a handle to DLL2.dll . I would like to
avoid using filenames, to keep things general.
I'm not sure, but perhaps GetModuleHandleEx may help?
http://msdn.microsoft.com/en-us/library/ms683200(VS.85).aspx
Something like that can be made to work for globals, but I don't see how it
would help if the modules are sharing the same heap, as they should be
given the derivation involved.
--
Doug Harrison
Visual C++ MVP