I have following function written in C++. How to properly declare and call it in C# using PInvoke?
SW_ErrCode SW_Connect (const char * server, int timeout, void * tag, SW_SessionID * sh_out)
In C# I have following Code:
public enum SW_ErrCode
{
SWERR_Success = 0,
SWERR_Truncated = 1,
SWERR_Connected = 3
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SW_SessionID
{
public int sessionId;
}
[DllImport("sw_api.dll")]
public static extern SW_ErrCode SW_Connect(string server, int timeout, IntPtr tag, out IntPtr sh_out);
static void Main(string[] args)
{
IntPtr infoPtr = new IntPtr();
IntPtr session;
int b = (int)SW_Connect("", 90, infoPtr, out session);
SW_SessionID s = (SW_SessionID)Marshal.PtrToStructure(session, typeof(SW_SessionID));
}
I believe that the biggest problem is with "void * tag" and "SW_SessionID * sh_out". How to properly use this function?
Thanks, K