none
Are DWORD_PTR and unsigned __int3264, signed __int3264 marshalled by COM/RPC as 64-bit values or 32-bit values? RRS feed

  • Question

  • Looking at the MIDL 64-bit porting guide, it seems to direct that pointer values should be passed using DWORD_PTR type on COM interfaces to successfully handle 32-bit and 64-bit platforms in a platform-independent way. However, some experimentation seems to indicate that the marshalling performed by MIDL-generated proxy/stub code on a 64-bit platform does not successfully marshal 64-bit values if they have non-0 values in the upper 4 bytes (i.e. only the lower 32-bits are actually transmitted).

    For example, server would like to return [out] DWORD_PTR * pPointerValue:
    *pPointerValue = 0x123456789ab;

    On the client side, I see value 0x456789ab (the 0x123 in upper 4bytes is lost and replaced with 0).

    Is this expected? If so, why does the MIDL porting guide indicate that DWORD_PTR should be useful for transmitting 8-byte pointer values across a marshalled interface?

    Is there some MIDL/IDL mechanism to support this in a platform-specific way (i.e. 32 bits on 32-bit platform and 64 bits on 64-bit platform)?

    If I specify unsigned __in64 * as the type in idl, then it transmits correctly, but I would like to have a platform-dependent data type that works correctly for both types of platforms.

    Thanks and regards,

    Jon

    Tuesday, June 5, 2018 8:31 PM

All replies

  • Hi,

    thanks for posting here.

    >>Are DWORD_PTR and unsigned __int3264, signed __int3264 marshalled by COM/RPC as 64-bit values or 32-bit values?

    The DWORD_PTR is a unsigned long type for pointer precision with enough bits so that a pointer can be converted to that type and back without losing information. It's declared as below:

    typedef ULONG_PTR DWORD_PTR;


    #if defined(_WIN64)
     typedef unsigned __int64 ULONG_PTR;
    #else
     typedef unsigned long ULONG_PTR;
    #endif

    Each of the types INT_PTR, UINT_PTR, LONG_PTR, ULONG_PTR, and DWORD_PTR is an integer type with the same size as a pointer: 32 bits in 32-bit code or 64 bits in 64-bit code.  The corresponding type in the .NET Framework is System.IntPtr or System.UIntPtr.

    For more information, you could refer to this similar case below.

    https://social.msdn.microsoft.com/Forums/en-US/fa7625e7-5001-4e15-a75a-83ead88f26a5/marshalling-dwordptr-used-in-dll-to-c

    Hope this could be help of you.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Baron Bi Thursday, June 21, 2018 5:45 AM
    Wednesday, June 6, 2018 8:14 AM