MFC DLL class problem...very strange!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Donald Sorenson (dony_s_at_excite.com)
Date: 09/22/04


Date: Wed, 22 Sep 2004 23:42:03 +0200

Well, here is the (strange!) situation. I wrote couple of classes that I
first test in an exe. Then I decided, to export them to an MFC DLL. I
created the DLL and of course, added the AFX_EXT_CLASS (this is not the
first time I'm doing that) to the headers. Now here is the really strange
thing. I'm calling the GetQueuedCompletionStatus(). This function returns
(among other things) an object pointer as part of the IOCP. The pointer that
this function returns (the overlapped pointer) and please be patient here,
is 4 bytes higher then the ACTUAL address of the formerly passed pointer… I
will make it clearer with an example… say I have allocated (and it doesn't
matter if it’s the stack or the free store) an overlapped structure and its
address is, let say, 0x00170000. Now, whenever GetQueuedCompletionStatus()
returns, its returning the value of 0x00170004 in the pointer!... now that
was working fine with the exe, but when passed to the DLL, I got that
strange effect. And no, 0x00170004 is not an address of some other class.
Now bypassing that is real easy, but I want to understand WHY this is
happening. I have created many class DLL like this, and this is the first
time I see something like this…Also, the pointer is allocated in the DLL and
the GetQueuedCompletionStatus()function call is also in the DLL, incase
someone need that info. Anyone has any idea…?



Relevant Pages

  • Re: new - delete issue
    ... EXE calls a DLL exported function that return a struct pointer. ... The EXE call another exported function that delete all pointers in that list. ...
    (microsoft.public.vc.mfc)
  • Re: Notify multiple instances of my COM dll to take an action
    ... my dll default interface is derived from IUnknown and the exe ... passing the pointer into the exe but the method call on that pointer ...
    (microsoft.public.vc.atl)
  • Re: Critical section shared betwen dll and main program
    ... different components like EXE and DLL. ... old version of CRITICAL_SECTION and passes a pointer to it which is used ... There is no problem with passing its address between exe and DLL. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Structure containing string across DLL boundary
    ... Exe and DLL both built with static RTL. ... Debug build has no issues. ... The DLL allocates the structure with the embedded string. ... The function in the exe is invoked with a pointer to the structure and then ...
    (microsoft.public.vc.stl)
  • Re: Critical section shared betwen dll and main program
    ... I would not suggest to pass pointer to any structure between ... different components like EXE and DLL. ... Binary Environment) bug. ... EXE, which was compiled in a newer environment, with another ...
    (microsoft.public.win32.programmer.kernel)