문제

i'm having problems calling a delphi function from C# (attempted to read or write protected memory), and was wondering what the correct way of calling the method should be. The Delphi function signature is as follows:

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

What is the correct way of calling this method from C#?

도움이 되었습니까?

해결책

The WideString is compatible with COM BSTR and so the .net marshaller should be able to consume it quite happily:

[DllImport(@"test.dll")]
private static extern void methodToCall(
    [MarshalAs(UnmanagedType.BStr)]
    string aFirstParameter,
    [MarshalAs(UnmanagedType.BStr)]
    ref string aSecondParameter
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top