I have a declaration and in the declaration, I want to set a height is a pointer to a double but get the error mesasage:
Error 1 Pointers and fixed size buffers may only be used in an unsafe context,
Can someone show me the right way to declare the type of pointer in a double ?
Below is mine declaration and I set the height to a pointer of double (double* height)
but gets an error message.
private static extern bool GetElevation(double dLat, double dLon, double* height);
Your extern declaration should probably be:
private static extern bool GetElevation(double dLat, double dLon, ref double height);
Hope this helps!
Edit
This question (and accepted answer) might shed some light on the subject. It talks about ref
vs out
(not sure which would fit better in your situation) and Marshalling.
I think you should:
private static unsafe extern bool GetElevation(double dLat, double dLon, double* height)
Once all that is done then you can compile with the /unsafe switch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With