locked
How to passed Reference parameter to WinRT component by C#?

    Question

  • I have a function in WinRT

    void test(int * ipt,int *opt) //(*ipt) and (*opt) will always be 0 here. {

    //(*ipt) = 5; //(*opt) = 1; } It maps to void test (out int ipt,out int opt) { } in C#

    but whatever i passed ipt and opt ,the (*ipt) and (*opt) always be 0,

    How can i  passed Reference parameter to WinRT? Although  I can achieve the goal  by  add parameters.



    • Edited by istring Tuesday, October 9, 2012 9:13 AM
    Tuesday, October 9, 2012 9:12 AM

Answers

  • 2 clarifications:

    - You cannot pass reference parameters. But you can pass out parameters. In the example above "void test(int* ipt, int* opt)" both parameters are treated as out parameters. So inside this method you cannot assume that you receive any value from the caller and you're expected to return a value yourself.

    - You can have native types part of the WinRT method signature as long as they are intrinsic types also supported by WinRT. int is supported.

    See also my response on this other thread: http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/408942d8-1a81-40dd-9de5-9ac877c6e2a4

    Thanks,
    Marian Luparu
    Visual C++

    • Marked as answer by istring Saturday, November 24, 2012 5:10 AM
    Thursday, November 8, 2012 7:04 PM
  • Hi,

    As far as I know, you can not pass the reference between Windows Runtime components.

    Second, the public type in components should be Windows Runtime types. We cannot pass a native type in components.

    You can call some function to change the value in a class, Please check this document
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh441569.aspx

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Jesse Jiang Wednesday, October 17, 2012 6:41 AM
    • Marked as answer by Jesse Jiang Wednesday, October 24, 2012 7:25 AM
    Tuesday, October 16, 2012 6:26 AM

All replies

  • Hi,

    As far as I know, you can not pass the reference between Windows Runtime components.

    Second, the public type in components should be Windows Runtime types. We cannot pass a native type in components.

    You can call some function to change the value in a class, Please check this document
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh441569.aspx

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Jesse Jiang Wednesday, October 17, 2012 6:41 AM
    • Marked as answer by Jesse Jiang Wednesday, October 24, 2012 7:25 AM
    Tuesday, October 16, 2012 6:26 AM
  • 2 clarifications:

    - You cannot pass reference parameters. But you can pass out parameters. In the example above "void test(int* ipt, int* opt)" both parameters are treated as out parameters. So inside this method you cannot assume that you receive any value from the caller and you're expected to return a value yourself.

    - You can have native types part of the WinRT method signature as long as they are intrinsic types also supported by WinRT. int is supported.

    See also my response on this other thread: http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/408942d8-1a81-40dd-9de5-9ac877c6e2a4

    Thanks,
    Marian Luparu
    Visual C++

    • Marked as answer by istring Saturday, November 24, 2012 5:10 AM
    Thursday, November 8, 2012 7:04 PM