How to pass structure by reference in WinRT Component C ++ / CX

My WinRT component has the following:

public value struct WinRTStruct
{
    int x;
    int y;
};

public ref class WinRTComponent sealed
{
    public:
    WinRTComponent();
    int TestPointerParam(WinRTStruct * wintRTStruct);
};

int WinRTComponent::TestPointerParam(WinRTStruct * wintRTStruct)
{
    wintRTStruct->y = wintRTStruct->y + 100;
    return wintRTStruct->x;
}

But it seems that the value of winRTStruct-> y and x is always 0 inside the method when called from C #:

WinRTComponent comp = new WinRTComponent();
WinRTStruct winRTStruct;
winRTStruct.x = 100;
winRTStruct.y = 200;
comp.TestPointerParam(out winRTStruct);
textBlock8.Text = winRTStruct.y.ToString();

What is the correct way to pass a structure by reference so that it is updated inside the WinRTC component method written in C ++ / CX?

+3
source share
2 answers

You cannot pass a structure by reference. All value types (including structures) in winrt are passed by value. Winrt structures are expected to be relatively small - designed for use in things like Point and Rect.

, struct "out" - "out" , . , , : "in" "out" ( / WinRT, JS , ).

+3

. WinRT , - ref struct:

public ref struct WinRTStruct2 sealed
{
private: int _x;
public:
 property int X
 {
    int get(){ return _x; }
    void set(int value){ _x = value; }
 }
private: int _y;
public:
 property int Y
 {
    int get(){ return _y; }
    void set(int value){ _y = value; }
 }
};

. VS11 INTERNAL COMPILER ERROR, ref, .

+1

All Articles