#pragma for value struct in WinRT component(C++) RRS feed

  • Question

  • Hello Everyone,

    I have a WinRT component(in C++) and I intend to use it in a C# Metro App.

    This WinRT component contains a custom struct as follows

    #pragma pack(1)
    public value struct MyStruct
    int int1;
    int int2;
    BOOLEAN bFlag1;
    BOOLEAN bFlag2;
    UINT32 dwValue;
    Platform::String^ MyStr;
    #pragma pack()

    On compilation I get the following error

    error C3621: 'myNamespace::MyStruct': only the default packing value (8) is allowed for WinRT types

    How do I go about solving this problem.

    Thanks for any help.


    Tuesday, August 7, 2012 1:33 PM

All replies

  • The error message is clear: you need to use the default packing for your WinRT type.

    If you need to have #pragma pack(1) in one place to communicate with code which requires that, but you can't use #pragma pack(1) elsewhere because you need to communicate with code which requires 8 then you will need to use separate structures at the communication boundary and marshal between them.

    Where it is best to do this will depend on the specific use case.


    Tuesday, August 7, 2012 5:52 PM