I'm trying to call few Delphi functions from C#:
MyType =array [1 .. 124] of byte
procedure f(bytes: MyType); stdcall;
external 'my.dll' name 'f';
That's my first problem. I've tried:
[DllImport("Delphi/my.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Auto)]
public static extern
void sygLadSyg([MarshalAs(UnmanagedType.LPArray)] byte[] myArray);
void sygLadSyg([MarshalAs(UnmanagedType.SafeArray)] byte[] myArray);
I get exception:
A call to PInvoke function 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.
What am I doing wrong?
Second problem is passing a bitmap.
function sygAnaliz(bitmapa: TBitmap): byte; stdcall;
external 'awSygnat1.dll' name 'sygAnaliz';
[DllImport("Delphi/awSygnat1.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi)]
public static extern
byte sygAnaliz(IntPtr bitmapPtr);
// and call itself
sygAnaliz(firstIMG.GetHbitmap());
I get exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Both functions are memory safe for sure, since they have been used for few years to great effect. Maybe there is something obvious that I miss?