【发布时间】:2019-06-26 10:08:16
【问题描述】:
我尝试了以下代码的几种变体,返回 HRESULT(这是更可取的 COM 标准)或返回 BSTR。我也尝试过其他数据类型。我通常会收到“缺少接口方法的实现”编译错误,但是当我使用 WideString 的返回类型时,result:=RetVal; 指令上有一个运行时 AccessViolationException。
我在客户端使用 C#:
var msg = delphi.GetMessage("My Message");
这里是 mi RIDL:
HRESULT _stdcall GetMessage([in] BSTR msg, [out, retval] BSTR* RetVal);
这是我的实现:
function TDelphiCom.GetMessage(msg:WideString; out RetVal:WideString):HRESULT;
var
tempString: string;
begin
tempString:=msg;
RetVal:=WideString(tempString);
end;
将字符串传入/传出 Delphi COM 服务器的正确方法是什么?
【问题讨论】:
-
这里的代码有什么问题?