Error Returning Float from C dll

  • Thread starter Thread starter beto
  • Start date Start date
B

beto

A am receiving an error when attempting to return a float from a C function.

The following is the C code

#define DLL __declspec(dllexport)

DLL float testfloat()
{
return 3.3;
}

The following is the C# code

[DllImport(".\\testfloat.DLL")]
static extern float testfloat();

float temp = testfloat();

Any help is appreciated.
 
beto said:
A am receiving an error when attempting to return a float from a C function.

What error are you receiving? I would also suggest that the interop
group might well give you useful answers, if no-one here knows.
 
A am receiving an error when attempting to return a float from a C function.
The following is the C code

#define DLL __declspec(dllexport)

DLL float testfloat()
{
return 3.3;
}

The following is the C# code

[DllImport(".\\testfloat.DLL")]
static extern float testfloat();

try specifying the "__stdcall" calling convention for the C++ function
ex.

DLL float __stdcall testfloat()
 
Jon Skeet said:
What error are you receiving? I would also suggest that the interop
group might well give you useful answers, if no-one here knows.

A managed NotSupportedException occurred at Application::Fun+0xf
 
Steve Waggoner said:
A am receiving an error when attempting to return a float from a C function.

The following is the C code

#define DLL __declspec(dllexport)

DLL float testfloat()
{
return 3.3;
}

The following is the C# code

[DllImport(".\\testfloat.DLL")]
static extern float testfloat();

try specifying the "__stdcall" calling convention for the C++ function
ex.

DLL float __stdcall testfloat()

Still received the same error message.
 
The solution that ended up working was to return just an integer that
reported the final status of the dll. To return the float, a reference
was passed to the dll and then used by the C# application.

Example:
[DllImport(".\\testfloat.dll")]
static extern int testfloat([In, Out] float[] returnf);

float[] returnf = new float[] {0,0,0,0};
int status = testfloat(returnf);
 
Back
Top