Hi all
I am using a dll written in C++ in a C# application. What is the equivalent for
char const *
unsigned short
in C#
thanks
Hi all
I am using a dll written in C++ in a C# application. What is the equivalent for
char const *
unsigned short
in C#
thanks
A char*
in C++ can have different meanings, e.g. a pointer to an array of bytes or an ANSI encoded null-terminated string. So it depends on the meaning of your data how the value can be marshaled to C#. The only answer that is definitively not wrong is: it's an IntPtr
.
A unsigned short
in C++ is usually a 16-bit unsigned integer: UInt16
(or ushort
in C#).
I looked at the code for your question and I think I got it worded better (check the intent). If so, you are looking for:
string
or byte[]
, depending on how the variable is used in the C code.ushort
, assuming unsigned short
produced by your C compiler is 16 bits. In C#, ushort
is always 16 bits (and uint
is always 32 bits). Congrats to MS for finally giving us some consistency here. :)To call a method exposed via an DLLImport, you'll want to use the IntPtr type for pointers.
Remember in C++ char* is actually a pointer to memory, usually represented by a 4 byte int.