struct output parameter

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

    #1

    struct output parameter

    In a Managed C++ module, I have a function returning an integer as
    output parameter:

    bool Func1( [System::Runtime ::InteropServic es::Out] int __gc *iout)
    {
    *iout = 33;
    return true;
    }

    Calling Func1 from a C# application works correctly:

    int iValue;
    Func1(out iValue); // iValue correctly returned as 33

    However, if using s struct parameter, I don't get the data returned

    MC++:

    __value struct MyStruct
    {
    public __value double dVal1;
    public __value double dVal2;
    };

    MyStruct m_data; // membe var

    bool Func2( [System::Runtime ::InteropServic es::Out] MyStruct __gc *pOut)
    {
    m_data.dVal1 = 11;
    m_data.dVal2 = 22;

    *pOut = m_data; // does not work - crashes application

    pOut = &m_data; // Function call succeedes, but m_data does not
    arrive in C# app
    return true;
    }

    C#:

    MyStruct data = new MyStruct ();
    Func2(out data); // data is empty

    How do I pass a struct output parameter correctly from MC++ to C# ???
    Any help is appreciated
    Regards Urs

  • Eric Gunnerson [MS]

    #2
    Re: struct output parameter

    It looks to me like the problem is on the C++ side. Have you tried the
    languages.vc newsgroup?

    --
    Eric Gunnerson

    Visit the C# product team at http://www.csharp.net
    Eric's blog is at http://blogs.gotdotnet.com/ericgu/

    This posting is provided "AS IS" with no warranties, and confers no rights.
    "Urs Wigger" <ns_urs.wigger@ leica-geosystems_ns.c om> wrote in message
    news:egcp2GcrDH A.648@TK2MSFTNG P11.phx.gbl...[color=blue]
    > In a Managed C++ module, I have a function returning an integer as
    > output parameter:
    >
    > bool Func1( [System::Runtime ::InteropServic es::Out] int __gc *iout)
    > {
    > *iout = 33;
    > return true;
    > }
    >
    > Calling Func1 from a C# application works correctly:
    >
    > int iValue;
    > Func1(out iValue); // iValue correctly returned as 33
    >
    > However, if using s struct parameter, I don't get the data returned
    >
    > MC++:
    >
    > __value struct MyStruct
    > {
    > public __value double dVal1;
    > public __value double dVal2;
    > };
    >
    > MyStruct m_data; // membe var
    >
    > bool Func2( [System::Runtime ::InteropServic es::Out] MyStruct __gc *pOut)
    > {
    > m_data.dVal1 = 11;
    > m_data.dVal2 = 22;
    >
    > *pOut = m_data; // does not work - crashes application
    >
    > pOut = &m_data; // Function call succeedes, but m_data does not
    > arrive in C# app
    > return true;
    > }
    >
    > C#:
    >
    > MyStruct data = new MyStruct ();
    > Func2(out data); // data is empty
    >
    > How do I pass a struct output parameter correctly from MC++ to C# ???
    > Any help is appreciated
    > Regards Urs
    >[/color]


    Comment

    Working...