开发者

How to call this Delphi function from C#?

开发者 https://www.devze.com 2023-02-17 09:07 出处:网络
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 signat

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 me开发者_运维百科thod 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
);
0

精彩评论

暂无评论...
验证码 换一张
取 消