I have a basic question,
I have a C++ unmanaged dll that have functions with parameters in and out some unsigned char,unsigned short,unsigned long,signed char,signed short, signed long data type.
Do I need to Marshal it or I can directly mapped it? What is the best practice if any?
e.g dll
unsigned long SomeFunc(unsigned char variableA);
C# (direct map in C#)
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.U4)]
public static extern uint SomeFunc(byte variableA);
To expand on the response of mozfox, the list is:
byte
,sbyte
,short
,ushort
,int
,uint
,long
,ulong
,IntPtr
,UIntPtr
,float
,double
, single-dimensional arrays ([]
) of those,struct
of those. Missing arebool
(that can be marshaled in various ways),char
(don't ask why... I don't know),string
.