C# reference to Cpp reference

R

Randy

Hi all,

I want to pass a reference from a C# app to a
managed CPP dll, keep getting the errors
Argument '1': cannot convert from 'out double' to 'double*'
Argument '2': cannot convert from 'out int' to 'int*'

I've been tying things till I'm red in the eyes....
Thanks for any help. I've searched the web several times,
and looked at maybe 0.0002% of the 1 GHits, haven't found
anything that helps.

I can use unsafe/fixed to get pointers in C#, but that
seems silly.

Randy


C# -----------
CClassM cls = new CClassM();
double A;
int B;
cls.DoSomething(out A, out B);
// also tried ref A, ref B

Managed CPP ------------------
public __gc class CClassM
{
CClassM() { }
~CClassM() { }

void DoSomething(double* pA, int* pB)
{ ........ }
// Also tried double&, int&
// Also tried [Out]double, [Out]int
// Also tried [Out]double*, [Out]int*
// Also tried [Out]double**, [Out]int**
};
 
M

Mattias Sjögren

void DoSomething(double* pA, int* pB)
{ ........ }
// Also tried double&, int&
// Also tried [Out]double, [Out]int
// Also tried [Out]double*, [Out]int*
// Also tried [Out]double**, [Out]int**
};

Make it

void DoSomething(double __gc* pA, int __gc* pB)

or

void DoSomething(Double* pA, Int32* pB)

and add the Out attribute if you want to use out rather than ref in
C#.



Mattias
 
R

Randy

Like a charm, and it even makes sense!

Thanks,
Randy
-----Original Message-----
void DoSomething(double* pA, int* pB)
{ ........ }
// Also tried double&, int&
// Also tried [Out]double, [Out]int
// Also tried [Out]double*, [Out]int*
// Also tried [Out]double**, [Out]int**
};

Make it

void DoSomething(double __gc* pA, int __gc* pB)

or

void DoSomething(Double* pA, Int32* pB)

and add the Out attribute if you want to use out rather than ref in
C#.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
.
 

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