int return parameter between C# and mc++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am invoking a mc++ method from C# via an unsafe code block. The reason for
the unsafe code block is that I am receiving a int as a return parameter. I
am invoking the method with a "ref iValue" int parameter.... and in the mc++
code I define "int* iValue" for the same int parameter. As a result I have
to place the invoking code in an unsafe code block.

Is there not a means to update a int parameter between C# and mc++ without
requiring the use of an unsafe code block ?

Thanks
 
As I answered in your other posting:

Or in a "safe" context:

C#
c.ModInt(ref i);

C++
1)
void ModInt3(System::Int32& i)
{
i = 13;
}

2)
void ModInt3(System::Int32* i)
{
*i = 13;
}

Willy.
 
OK...this works fine.

One more related question. What if I prefer to invoke the method with the
"out" modifier.... like...

C#
c.ModInt(out i);

How is the parameter defined in mc++ to accomodate the "out" requirement ?

Thanks

Philip
 
Specify the OutAttribute on the formal argument you want to pass as out.
Note that this attribute only as a real value when using interop (COM or
PInvoke), but here it
makes the CSsharp compiler happy ;-)

ModInt(out i);

...

MC++
void ModInt([System::Runtime::InteropServices::OutAttribute]
System::Int32& i)
{
i = 3;
}

Willy.
 
Back
Top