convert to double *

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

Guest

How could I pass a double* argument form my C# application to C++ assembly code which has the following prototype
void abc(double * a, int nArgs

...


Thanks
 
Hi,
Sagiv said:
How could I pass a double* argument form my C# application to C++ assembly
code which has the following prototype:
void abc(double * a, int nArgs)
{
...
}

If "a" is an array :

[ImportDll("...")]
public static void abc([In,Out]double[] a, int nArgs);

The callee can change the array, but it cannot change the size and to access
the array safely the callee should know the size, maybe trough nArgs.

Otherwise:

[ImportDll("...")]
public static void abc( ref double a, int nArgs );

hth,
greetings
 
Hi,
Thanks, in my case it's not a dll which I call, but a managed C++ code, therefore I have to call it directly
Is there a way to pass an argument from C# which is of type double *

Thanks a lot for your reply
Sagiv
 
Sagiv said:
Hi,
Thanks, in my case it's not a dll which I call, but a managed C++ code,
therefore I have to call it directly.
Is there a way to pass an argument from C# which is of type double * ?

No, double* isn't managed.

void abc(double __gc * a, int nArgs)
void abc(double __gc & a, int nArgs)
void abc(System::Double * a, int nArgs)
void abc(System::Double & a, int nArgs)

These functions are all valid mc and the 'a' parameter would be a 'ref
double' in c#.

hth,
greetings
 
Thanks, in my case it's not a dll which I call, but a managed C++ code,
therefore I have to call it directly.
Is there a way to pass an argument from C# which is of type double * ?

What do you mean with directly? You cannot call code from an .exe or a .obj
file. You must compiler your c++ code into a dll, exporting the functions
you want to cann from your C# app.

If you are using managed C++, you can simply add your C++ project in your
workspace and call it exactly as you would call your C# stuff. Don't forget
to add the project reference to the c++ project in your c# project.
 
Is there a way to pass an argument from C# which is of type double * ?

Yes, in an unsafe code block

double d = 123.45;
unsafe {
yourMCPPObject.YourMethod( &d );
}



Mattias
 
Back
Top