I need to call a function from C api contained in a dll. The prototype of the function is as follows.
int func( char* name, void* value );
where the contents of a pointer value can refer to any type depending on the name passed. I am not sure how to configure inport dll to properly sort this void *. I experimented with IntPtr, which seems to work, and the value is int, but I cannot get the values ββfor float properly, etc.
I am trying to import a function like this ...
[DllImport("dllname.dll", CharSet = CharSet.Ansi)] public static extern int func( string name, ref IntPtr value );
Note that the value is the result. A pointer to a value of any type, that is, an address in the global memory region of a value of a known type (known to the caller). In c prog, the caller would have to cast that void * to the desired type and dereference to get the actual value stored there. The answers given so far seem to be based on the assumption that the function will write the result to the location of the pointer passed. My mistake, as I was not too specific. I'm sorry. C # is not my bag, and I donβt even know if IntPtr has a way here ...
c #
matt
source share