I'm attempting to call an unmanaged DLL from C#. I've very little experience with unmanaged code and P\Invoke so I was hoping for an extra pair of eyes.
I don't have much information of the DLL except the function:
int Initialize(char *FileName, int Driver, int(*InfoLine)(char*), char *Message);
Infoline can be null.
So this is what I did in C#.
The import call:
[DllImport(@"c:\Core\initialization.dll", EntryPoint="Initialize", CharSet = CharSet.Auto)]
private static extern int Initialize([MarshalAs(UnmanagedType.LPStr)] string FileName, int Driver, System.IntPtr InfoLine, [MarshalAs(UnmanagedType.LPStr)] string Message);
The method call is:
IntPtr infoLine = IntPtr.Zero;
string message = "";
int success = Initialize(@"c:\config.dat", -1, infoLine, message);
The error message that Visual Studio gives back to me in debug mode is:
A call to PInvoke function 'Initialize' 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.
Which parameter have I passed incorrectly?
I am fairly certain that the call to the DLL is correct because there is another function that has no parameters passed and similar import and method code worked.
Thanks for the help.