I am calling functions from a unmanaged dll in C#. And one of my calls to this dll is working. But the other one has more advanced Parameters and when I execute the Funkction in my C# Code:
[DllImport("IOLUSBIF20.dll", CallingConvention = CallingConvention.StdCall)]
public static extern long IOL_SetTransparentModeExt(long Handle, UInt32 Port, ref TTransparentParameters pTransparentParameters);
I get the following Error:
"PInvokeStackImbalance" : "A call to PInvoke function 'IO-Link Device Interface!IO_Link_Device_Interface.IOLUSBIF20Wrapper::IOL_SetTransparentModeExt' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."
In the Header the signature of the function (and the struct) is defined as follows:
LONG __stdcall IOL_SetTransparentModeExt(LONG Handle, DWORD Port, TTransparentParameters * pTransparentParameters);
typedef struct TTransparentParametersStruct
{
BYTE StartPattern[16]; /**< starting pattern */
BYTE ReturnPattern[32]; /**< returning pattern */
} TTransparentParameters;
The struct that I pass as an Argument Looks as follows:
[StructLayout(LayoutKind.Sequential)]
public struct TTransparentParameters
{
public Byte[] StartPattern; /**< starting pattern */
public Byte[] ReturnPattern; /**< returning pattern */
}