none
ATL using struct in x64

    Question

  • I have a ATL project using MFC in vs2008, and I defined two struct in .idl, then wrote a function to return it.
    When I build it to win32, it works perfect, but when I build it to x64, the struct data will be strange.

    szCompNum becomes null, and szTitle becomes szCompNum.
    How do I solve situation? 

    thanks

    [
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE3099),
    	version(2.0),
    	helpstring("Invoice variable")
    ]
    typedef struct InvoiceInfo{
    	LONG nInstallmentPeriod;
    	LONG nFirstAMT;
    	LONG nEachAMT;
    	BSTR szCompNum;
    	BSTR szTitle;
    	BSTR szAddr;
    } InvoiceInfo;
    
    [
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE3098),
    	version(2.0),
    	helpstring("Transaction variable")
    ]
    typedef struct TransInfo{
    	LONG nInstallmentPeriod;
    	LONG nFirstAMT;
    	LONG nEachAMT;
    	InvoiceInfo invoice
    	BSTR szTransMode;
    	BSTR szInstallmentType;
    	BSTR szRedeemType;
    } TransInfo;
    
    [
    	object,
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE302F),
    	dual,
    	nonextensible,
    	helpstring("IPOSQrPay Interface"),
    	pointer_default(unique)
    ]
    interface IPay : IDispatch{
    	[id(8)] HRESULT ComResult([in] BSTR szSystemID, [out] TransInfo* info, [out,retval] LONG* returnVal);
    }



    Tuesday, June 11, 2013 3:31 AM

Answers

  • I try to add below declare pragma on my struct area then it work!

    what's defferent between pragma pack and the Struct Member Alignment??

    #pragma pack(push)
    #pragma pack(1)
    [
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE3099),
    	version(2.0),
    	helpstring("Invoice variable")
    ]
    typedef struct InvoiceInfo{
    	LONG nInstallmentPeriod;
    	LONG nFirstAMT;
    	LONG nEachAMT;
    	BSTR szCompNum;
    	BSTR szTitle;
    	BSTR szAddr;
    } InvoiceInfo;
    
    [
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE3098),
    	version(2.0),
    	helpstring("Transaction variable")
    ]
    typedef struct TransInfo{
    	LONG nInstallmentPeriod;
    	LONG nFirstAMT;
    	LONG nEachAMT;
    	InvoiceInfo invoice
    	BSTR szTransMode;
    	BSTR szInstallmentType;
    	BSTR szRedeemType;
    } TransInfo;
    
    [
    	object,
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE302F),
    	dual,
    	nonextensible,
    	helpstring("IPOSQrPay Interface"),
    	pointer_default(unique)
    ]
    #pragma pack(pop)

    Friday, July 05, 2013 2:00 AM

All replies

  • On 6/10/2013 11:31 PM, Shelly Chen星寂 wrote:

    I have a ATL project using MFC in vs2008, and I defined two struct in .idl, then wrote a function to return it.
    When I build it to win32, it works perfect, but when I build it to x64, the struct data will be strange.

    szCompNum becomes null, and szTitle becomes szCompNum.
    How do I solve situation?

    Make sure you have the same struct alignment for both the C++ and MIDL compilers, in both 32-bit and 64-bit configurations (pay attention to Configuration and Platform drop-downs at the top of the Properties dialog).

    Project | Properties | C/C++ | Code Generation | Struct Member Alignment
    Project | Properties | MIDL | Advanced | Struct Member Alignment


    Igor Tandetnik

    Tuesday, June 11, 2013 3:56 AM
  • thanks, it works!

    I change all of them to 4 Bytes (/Zp4).

    Tuesday, June 11, 2013 4:08 AM
  • I found another question. I change all of them to 4 Bytes (/Zp4).

    string data is correct, but the long data is wrong.

    correct:

    nInstallmentPeriod = 12000, nFirstAMT = -1, nEachAMT = -1

    wrong:

    nInstallmentPeriod = 2046, nFirstAMT = 12000, nEachAMT = -1

    if I change all of options to 8 Bytes, the string data is wrong.


    Tuesday, June 11, 2013 5:05 AM
  • who is consuming this server, i mean in what language is the client code developed?

    is the server a in-proc or out-proc , is the server and client located on the same machine.

    if not, did you register the server both at the client and server after making these changes ?

    Tuesday, June 11, 2013 10:14 AM
  • I use this ATL by regsvr32 in my pc,  then add reference in C# console for testing.

    client and server is on the same machine.

    My develope pc is WIN7 x64 Ultimate.

    Thursday, June 13, 2013 1:41 PM
  • try adding these in struct declaration

    [ComVisible(true)] [StructLayout(LayoutKind.Sequential)]

    and  right-click the reference to the COM object and set Embed Interop Type to False. 

    Thursday, June 13, 2013 2:37 PM
  • I don't have the Embed Interop Type attribute. I checked properties window, the file type is ActiveX not COM.

    When I created the VS2008 ATL project, I used dll, support MFC.

    Where is the declaration to add ??  .idl file? C# code doesn't defined the struct, when I added reference to ATL object , the struct could be used.

    thanks for your help~

    Friday, June 14, 2013 2:41 AM
  • Maybe a reproducible project is needed...

    Reply, then visible.

    Monday, June 17, 2013 6:03 AM
  • I try to add below declare pragma on my struct area then it work!

    what's defferent between pragma pack and the Struct Member Alignment??

    #pragma pack(push)
    #pragma pack(1)
    [
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE3099),
    	version(2.0),
    	helpstring("Invoice variable")
    ]
    typedef struct InvoiceInfo{
    	LONG nInstallmentPeriod;
    	LONG nFirstAMT;
    	LONG nEachAMT;
    	BSTR szCompNum;
    	BSTR szTitle;
    	BSTR szAddr;
    } InvoiceInfo;
    
    [
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE3098),
    	version(2.0),
    	helpstring("Transaction variable")
    ]
    typedef struct TransInfo{
    	LONG nInstallmentPeriod;
    	LONG nFirstAMT;
    	LONG nEachAMT;
    	InvoiceInfo invoice
    	BSTR szTransMode;
    	BSTR szInstallmentType;
    	BSTR szRedeemType;
    } TransInfo;
    
    [
    	object,
    	uuid(4E3933AC-E890-49C7-AF65-1117BACE302F),
    	dual,
    	nonextensible,
    	helpstring("IPOSQrPay Interface"),
    	pointer_default(unique)
    ]
    #pragma pack(pop)

    Friday, July 05, 2013 2:00 AM
  • http://software.intel.com/en-us/forums/topic/297934

    Reply, then visible.

    Monday, July 08, 2013 7:29 AM