struct output parameter

U

Urs Wigger

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

bool Func1( [System::Runtime::InteropServices::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::InteropServices::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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top