I'm assuming that your target platform is Windows, based on the name of your library in the DllImport
attribute. On Windows, the C++ long
type (unsigned as well as signed, obviously) is 4 bytes wide, for both 32 and 64 bit. So, you need to declare your p/invoke using uint
rather than ulong
.
The correct declaration is:
[DllImport("C:/my.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern uint OpenPort(
uint ulPort,
uint ulBaudRate,
uint ulByteSize,
uint ulParity,
uint ulStopBits,
uint ulFlowControl
);
Now, if your target platform is other than Windows, then you'd need to know what unsigned long
is on that platform to give specific advise.