C# Invoking MC++

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

Guest

I have a C# program invoking a MC++ method. One of the output parameters is
an "int".... defined as "int iretval". In the C# program I want to pass the
parameter as either "ref iretval" or "out iretval". In each case..... how
must the corresponding "int" be defined in the MC++ method ?.... so that it
is compile-error free ?

Help ...
 
Philip said:
I have a C# program invoking a MC++ method. One of the output parameters
is
an "int".... defined as "int iretval". In the C# program I want to pass
the
parameter as either "ref iretval" or "out iretval". In each case.....
how
must the corresponding "int" be defined in the MC++ method ?.... so that
it
is compile-error free ?

Help ...

int *iretval

Willy.
 
I have tried that.... I get the following compiler error...

error CS1503: Argument '3': cannot convert from 'ref int' to 'int*'

Do you have any other suggestions ?

Philip
 
Sorry, we are talking IJW. Enter the unsafe context....

C#
int i;
unsafe {c.ModInt(&i);}

C++
void ModInt(int* i)
{
*i = 123;
}

Willy.
 
Or:
C#
unsafe {
c.ModInt(&i);
...


C++
void ModInt(int& i)
{
i = 123;
}

Willy.
 
Philip said:
I have tried that.... I get the following compiler error...

error CS1503: Argument '3': cannot convert from 'ref int' to 'int*'

Do you have any other suggestions ?

Philip

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;
}

That's all I can think about.
Note that if you pass anything that is not stack allocated to unmanaged code
you need to pin the variable..

Willy.
 
Back
Top