I have an unmanaged DLL I am referencing in my project using [DLLImport]
, but am receiving odd results when I match method signatures.
Here is an example signature from the DLL:
DLLEXPORT unsigned long OpenPort(unsigned long ulPort,
unsigned long ulBaudRate,
unsigned long ulByteSize,
unsigned long ulPartity,
unsigned long ulStopBits,
unsigned long ulFlowControl)
And here is my C# code to import the function:
[DllImport("C:/my.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern uint OpenPort(ulong ulPort, ulong ulBaudRate,
ulong ulByteSize, ulong ulParity, ulong ulStopBits, ulong ulFlowControl);
Notice I declare this with a return type of uint
, as when I attempt to use ulong
I get unexpected results (long numbers usually that look a bit like memory addresses).
However, the function works and returns expected results if I use a return type of int
/uint
. Can anyone shed any light on this behaviour for me?
Thanks.