How to call this Delphi function from C #?

I had problems calling the delphi function from C # (trying to read or write protected memory) and wondered what the correct way to call the method should be. The signature of the Delphi function is as follows:

procedure methodToCall(
    aFirstParameter: Widestring; 
    var aSecondParameter: Widestring
    ); stdcall;

What is the correct way to call this method from C #?

+3
source share
1 answer

WideString is compatible with COM BSTR, and so the .net marshaller should be able to use it pretty happily:

[DllImport(@"test.dll")]
private static extern void methodToCall(
    [MarshalAs(UnmanagedType.BStr)]
    string aFirstParameter,
    [MarshalAs(UnmanagedType.BStr)]
    ref string aSecondParameter
);
+7
source

All Articles