How to use double as return value in Platform invoke?

G

Guest

I have a function called GetDoubleData in dll. I would like to declare it in
C#. I have tried the following, but there is an exception ("NotSupported
Exception was unhandled")

Pleeeeeeeeease help me!

Form1.cs

public double doubleData
{
get { return GetDoubleData(); } // "Not supported Exception
unhandled"
}

[DllImport("itscpp.dll", EntryPoint = "GetDoubleData", SetLastError = true)]
public static extern double GetDoubleData();

itscpp.h:

extern "C" __declspec(dllexport) double GetDoubleData();

itscpp.cpp:

__declspec(dllexport) double GetDoubleData()
{
return myData.DoubleData;
}

Thanks,

Frankie
 
P

Peter Foot [MVP]

Declare your native function to pass a pointer to a double to return the
value, you'd then declare this in a P/Invoke as
[DllImport("itscpp.dll", EntryPoint = "GetDoubleData", SetLastError = true)]
public static extern void GetDoubleData(ref double theValue);

Peter
 

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