64-bit COM dll structure access

Discussion in 'Windows 64bit' started by yezdived@gmail.com, Mar 7, 2006.

  1. Guest

    I've a COM 64-bit dll built with Windows 2003 SP1 SDK April 2005
    edition on Windows XP SP2. All MIDL options and project settings are
    done correctly (as far as i know) to build the 64-bit DLL.
    This DLL defines a structure of the form
    typedef struct sVALIDATION
    {
    UINT32 unDataLen;
    BYTE *pData;
    }S_VALIDATION;
    and has an interface method to fill up this structure of the form:
    HRESULT FillUpStructure([in,out,ptr]S_VALIDATION *pSValidation);
    {
    //pseudo code
    pSValidation->unDataLen = 3;
    pSValidation->pData = (BYTE *)CoTaskMemAlloc(3);
    //... set bytes
    }

    Now I'm using the tlb generated above, in my client application and
    calling the FillUp method
    //pseudo code
    #import COM64.tlb
    using namespace COM64Lib;
    void main()
    {
    S_VALIDATION sValid;
    memset(&sValid,0,sizeof(sValid));
    try
    {

    IValidationPtr pValidation =
    IValidationPtr(__uuidof(ValidationClass));
    //....
    pValidation->FillUpStructure(&sValid);
    wprintf(L"%d",sValid.unDataLen); // prints "3" correctly

    wprintf(L"%X",sValid.pData[0]); //throw up here
    }
    catch(...)
    {
    //....
    }
    //cleanup code
    }
    QUESTION:
    When I'm accessing the pData value, it is throwing error. I debugged on
    XP x64 machine and noticed
    that pData pointer occupies 8 bytes. But when it returns from the
    method call, the higher 4 bytes are being set
    so the client code ends up accessing value at [00a1308e'00000000]
    instead of [00000000'00a1308e] where actual data is present.

    pData pointer before the call as seen in memory window {00 00 00 00 00
    00 00 00}
    pData pointer after the call as seen in memory window {00 00 00 00 8e
    30 a1 00}

    Why is it happening this way? I started stepping through code and went
    little deep where RPCRT4!.... module doing some unmarshalling stuff.. I
    didn't understand this part and quit. Please help me.

    Thanks in advance,
    Vedala
     
    , Mar 7, 2006
    #1
    1. Advertising

  2. Guest

    Hi,
    I've found what is causing this issue.. when I'm importing the TLB file
    #import "COM64.tlb" the tlh which is generated has compiler inserted
    pack pragma around the structure definition
    ##pragma pack(push, 8) //module level due to /Zp8

    #pragma pack(push, 4)
    struct sVALIDATION
    {
    UINT32 unDataLen;
    BYTE *pData;
    }S_VALIDATION;
    #pragma pack(pop)
    .....
    .....
    #pragma pack(pop) //module level


    Due to this my client code got compiled with 4-byte alignment of this
    structure while server dll got compiled with 8-byte alignment. This
    happened even-though I've set module-level option /Zp8 for my client
    project options.

    Now my question is how should I tell the compiler to use 8-byte
    alignment on this structure during generation of tlh file via #import
    "COM64.tlb"?
    Thanks in advance.
     
    , Mar 8, 2006
    #2
    1. Advertising

  3. Rob Perkins Guest

    wrote:

    > Due to this my client code got compiled with 4-byte alignment of this
    > structure while server dll got compiled with 8-byte alignment. This
    > happened even-though I've set module-level option /Zp8 for my client
    > project options.


    I wonder if these sorts of problems could happen to an "AnyProc"
    compiled IL DLL assembly, cause I think you summarized in four lines why
    Microsoft when to all the trouble of making C# in the first place... :)

    Rob
     
    Rob Perkins, Mar 8, 2006
    #3
  4. I'm sure it'll help him with his problem
     
    Mike Gleason jr Couturier, May 4, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fred Valentino

    TOOLBAR.DLL & KERNAL32.DLL

    Fred Valentino, Nov 12, 2003, in forum: Computer Support
    Replies:
    2
    Views:
    603
    Boomer
    Nov 12, 2003
  2. Sparky
    Replies:
    3
    Views:
    24,740
    Sparky
    Jan 24, 2004
  3. Some1

    mprapi.dll --> samlib.dll --> ntdll.dll issue.

    Some1, Apr 2, 2004, in forum: Computer Support
    Replies:
    4
    Views:
    2,395
    Some1
    Apr 5, 2004
  4. Snoopy
    Replies:
    16
    Views:
    3,216
    Mainlander
    Aug 25, 2003
  5. Mahesh Gothi

    how to run 32 bit java dll on 64 bit machine

    Mahesh Gothi, Nov 23, 2009, in forum: Windows 64bit
    Replies:
    0
    Views:
    1,188
    Mahesh Gothi
    Nov 23, 2009
Loading...

Share This Page