frustrating parameter issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vinz

    frustrating parameter issue

    Hello everyone,

    My question is part C# and part C++. Please don't kill me for bringing C#
    inhere :-) Also please don't kill me for asking a n00b question, I'm still
    new to C++/CLI and C#.


    I have an assembly written in C++/CLI with a public function:

    int MyClass::MyFunc tion(String ^x) {
    x = "zzz";
    return 0;
    };


    I want to call this function from a C# app and show the changed contents of
    variable

    MyClass TheClass = new MyClass();
    String w = "m";
    TheClass.MyFunc tion(w);
    MessageBox.Show (w);


    When executing, the messagebox shows 'm', and I want it to show 'zzz'.

    What am I doing wrong here???

    Thanks for reading sofar.

    Vince.


  • David Lowndes

    #2
    Re: frustrating parameter issue

    >I want to call this function from a C# app and show the changed contents of
    >variable
    Vince,

    You need to define the function parameter as a tracking reference -
    see "% Tracking Reference" in MSDN.

    Dave

    Comment

    • =?Utf-8?B?RGF2aWQgQW50b24=?=

      #3
      RE: frustrating parameter issue

      int MyClass::MyFunc tion(String ^%x) {
      x = "zzz";
      return 0;
      };

      --
      David Anton
      Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

      Instant C#: VB to C# converter
      Instant VB: C# to VB converter
      Instant C++: C#/VB to C++ converter
      Instant Python: C#/VB to Python converter


      "Vinz" wrote:
      Hello everyone,
      >
      My question is part C# and part C++. Please don't kill me for bringing C#
      inhere :-) Also please don't kill me for asking a n00b question, I'm still
      new to C++/CLI and C#.
      >
      >
      I have an assembly written in C++/CLI with a public function:
      >
      int MyClass::MyFunc tion(String ^x) {
      x = "zzz";
      return 0;
      };
      >
      >
      I want to call this function from a C# app and show the changed contents of
      variable
      >
      MyClass TheClass = new MyClass();
      String w = "m";
      TheClass.MyFunc tion(w);
      MessageBox.Show (w);
      >
      >
      When executing, the messagebox shows 'm', and I want it to show 'zzz'.
      >
      What am I doing wrong here???
      >
      Thanks for reading sofar.
      >
      Vince.
      >
      >
      >

      Comment

      • Vinz

        #4
        Re: frustrating parameter issue

        Thanks very much guys :-)

        I tried to use the % before but that doesn't compile. ^% compiles though. I
        had to also use ref x instead of just x in the C# call too btw.

        Anyway, I got it working now, thanks a lot :-)

        Vince.

        "David Anton" <DavidAnton@dis cussions.micros oft.comwrote in message
        news:D350ACB7-EDF2-4D50-BC99-81E0CFDCDC5C@mi crosoft.com...
        int MyClass::MyFunc tion(String ^%x) {
        x = "zzz";
        return 0;
        };
        >
        --
        David Anton
        Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

        Instant C#: VB to C# converter
        Instant VB: C# to VB converter
        Instant C++: C#/VB to C++ converter
        Instant Python: C#/VB to Python converter
        >
        >
        "Vinz" wrote:
        >
        >Hello everyone,
        >>
        >My question is part C# and part C++. Please don't kill me for bringing C#
        >inhere :-) Also please don't kill me for asking a n00b question, I'm
        >still
        >new to C++/CLI and C#.
        >>
        >>
        >I have an assembly written in C++/CLI with a public function:
        >>
        >int MyClass::MyFunc tion(String ^x) {
        > x = "zzz";
        > return 0;
        >};
        >>
        >>
        >I want to call this function from a C# app and show the changed contents
        >of
        >variable
        >>
        >MyClass TheClass = new MyClass();
        >String w = "m";
        >TheClass.MyFun ction(w);
        >MessageBox.Sho w(w);
        >>
        >>
        >When executing, the messagebox shows 'm', and I want it to show 'zzz'.
        >>
        >What am I doing wrong here???
        >>
        >Thanks for reading sofar.
        >>
        >Vince.
        >>
        >>
        >>

        Comment

        Working...