I am using dllImport to use a C library in C# .NET. One of the methods in this library uses data type void* as parameter. I found out, that I can use the data type IntPtr in C# matching the void*.
Now I simply don't know how to set the value of this IntPtr parameter. In fact I want to put a float value into this parameter. How would I do this?
Thanks in advance for any idea. Simone
If you can use unsafe blocks, this one works:
static IntPtr IntPtrFromFloat( float f )
{
unsafe
{
return (*(IntPtr*)&f);
}
}
It creates an IntPtr containing an address equal to the binary representation of the float.
It should also be possible to just declare the parameter as float. It is 32bits anyway [32bit C-DLL assumed].
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