C#'s REF or OUT in Managed C++

  • Thread starter Thread starter Ryan Gregg
  • Start date Start date
R

Ryan Gregg

I'm working on creating a wrapper for some old code we have in C++ so that
we can call it from a C# program. In C++ we have several functions defined
that use the following notation:

static long CalcCPL(double API60, double Temperature, double Pressure,
double& ComputationalCPL, double& PrintingCPL);

Where the double& arguments are output values from the function call. When
I compile these into a managed C++ class, and try to use it from inside a C#
program, I get the following message:

C:\Class1.cs(27): Argument '3': cannot convert from 'out double' to
'double*'
C:\Class1.cs(27): Argument '4': cannot convert from 'out double' to
'double*'
C:\Class1.cs(27): Argument '5': cannot convert from 'out short' to 'short*'

I've tried defining the function using the [Out] attribute or the [Ref]
attribute, but I get the same errors. Can someone help me figure out what
I'm doing wrong?

Thanks.

Ryan Gregg
 
Ryan,
static long CalcCPL(double API60, double Temperature, double Pressure,
double& ComputationalCPL, double& PrintingCPL);

To get a ref parameter you change it to

Double ComputationalCPL

or

double __gc & ComputationalCPL

To make it out, add the [Out] attribute.



Mattias
 
Thank you!! That solved my problem.

Ryan Gregg


Mattias Sjögren said:
Ryan,
static long CalcCPL(double API60, double Temperature, double Pressure,
double& ComputationalCPL, double& PrintingCPL);

To get a ref parameter you change it to

Double ComputationalCPL

or

double __gc & ComputationalCPL

To make it out, add the [Out] attribute.



Mattias
 
Back
Top