I’ve got a “native” DLL with some nice functions that can return (and accept) pointers to data which is formatted according to particular C structs.
In my C# program I don’t care about the struct internals, I just want to get and pass them from/to the native functions. I’ve already managed to pinvoke the functions inside the DLL.
For to pointers, I’ve thought of using void* (as a “pointer-to-unknown”), since I really don’t care the internal fields of the pointed structs, I just need to store and use the pointers to pass it to the DLL library functions.
But using void* for many different kinds of data makes my code unreadable! Is there any way in C# to typedef void* some_nicer_type_t ? Or to do something like that?
You could consider using
IntPtrinstead.From MSDN:
This may ultimately aid you in writing non-
unsafecode, too.EDIT:
To address your desired needs as reiterated in comment to this question, one thing I might suggest (though not proposing this to be ideal) is to define a
structorclasswhich is essentially a wrapper around a pointer:As you yourself bring up, this may lead to wrapping even more code in order to have it all conform to the usage and aesthetics of usage that you want.