locked
Passing Platform::String^ in a struct to and from WinRT component

    Question

  • Hello Everyone,

    I have a value struct in my WinRT component(C++) as follows

    public value struct MyStruct
    {
    int int1;
    int int2;
    BOOLEAN bFlag1;
    BOOLEAN bFlag2;
    UINT32 dwValue;
    Platform::String^ MyStr;

    };

    This WinRT component contains an exported function that is responsible for filling this structure. This function is then called from a C# app.

    I get the values of all fields except the string MyStr in the C# app. How do I read and write this structure.

    Thanks for any help.

    Regards.

    Monday, August 06, 2012 6:22 AM

Answers

  • 	public ref class Class1 sealed
    	{
    	public:
    		Class1();
    		MyStruct CreateStruct()
    		{
    			MyStruct s;
    			s.int1 = 1;
    			s.int2 = 2;
    			s.bFlag1 = true;
    			s.bFlag2 = false;
    			s.dwValue = 0xFF;
    			s.MyStr = ref new Platform::String(L"Test String");
    			return s;
    		}
    	};

    • Proposed as answer by Jesse Jiang Tuesday, August 07, 2012 7:15 AM
    • Marked as answer by NewBieDev2012 Tuesday, August 07, 2012 7:18 AM
    Monday, August 06, 2012 9:57 PM
    Moderator

All replies

  • 	public ref class Class1 sealed
    	{
    	public:
    		Class1();
    		MyStruct CreateStruct()
    		{
    			MyStruct s;
    			s.int1 = 1;
    			s.int2 = 2;
    			s.bFlag1 = true;
    			s.bFlag2 = false;
    			s.dwValue = 0xFF;
    			s.MyStr = ref new Platform::String(L"Test String");
    			return s;
    		}
    	};

    • Proposed as answer by Jesse Jiang Tuesday, August 07, 2012 7:15 AM
    • Marked as answer by NewBieDev2012 Tuesday, August 07, 2012 7:18 AM
    Monday, August 06, 2012 9:57 PM
    Moderator
  • Hello Steve,

    Thanks for the reply. I will try your solution and let you know.

    Regards.

    Tuesday, August 07, 2012 7:18 AM