I am trying to call a method created in Delphi as follows:
function _Func1(arrParams: array of TParams): Integer;stdcall; type TParams = record Type: int; Name: string; Amount : Real; end;
My code is:
[DllImport("some.dll", EntryPoint = "_Func1", CallingConvention = CallingConvention.StdCall)] public static extern int Func( [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct)] TParams[] arrParams)
And structure:
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct TParams { public int Type; [MarshalAs(UnmanagedType.AnsiBStr)] public string Name; public double Amount; }
When I call this method, I get the error: Unable to display the "Name" field of type "TParams": Invalid combination of managed / unmanaged types (String fields must be paired with LPStr, LPWStr, BStr or ByValTStr).
However, none of these combinations work, since Delphi strings have a prefix of their length, and this is certainly Ansi (I tried this with other string parameters). Does anyone know how to solve this?
xurc source share