我正在努力实现一个来自C动态链接库的函数。它的声明如下:
int DetectTransactionCode(wchar_t* wi_type, wchar_t* wi_id);
如果我在Delphi代码中声明并调用了以下内容:
function DetectTransactionCode (var wi_type, wi_id: PWideChar): Integer;
cdecl; external 'WiGroupDetect.dll';
procedure TForm20.Button2Click(Sender: TObject);
var witype,wi_id : widestring;
res : integer;
begin
res := DetectTransactionCode(PWideChar(witype),PWideChar(wi_id));
showmessage(res.tostring);
ShowMessage(witype +' & ' +wi_id);
end;
我收到了结果,但是我的witype和wi_id导致了访问冲突。
我也尝试过:
Function DetectTransactionCode (var witype,wi_id :widestring ) : Integer cdecl;
external 'WiGroupDetect.dll';
procedure TForm20.Button2Click(Sender: TObject);
var witype,wi_id : widestring;
res : integer;
begin
res := DetectTransactionCode(witype,wi_id);
showmessage(res.tostring);
ShowMessage(witype +' & ' +wi_id);
end;
我假设这两个参数都是输出参数。第三方提供了以下内容:
成功返回1,取消/失败返回0
注意: 阻塞调用仅在以下情况下返回: 1- 检测到wiCode, 2- 调用KillDetectionProcess(), 3- 发生某些错误或失败, 或者 4- 最终超时(30分钟)。
参数: wi_type 在成功时返回检索到的标记类型(例如“WIQR”表示QR); 在取消/失败时返回“NONE”。 wi_id 成功时返回检测到的wiCode; 取消时返回“CANCELLED”; 失败时返回附加的错误信息(例如“ERROR: …”)。
我尝试将参数更改为ansistring、unicodestring,但仍然遇到相同的问题。我怀疑这与var参数有关,但不确定如何克服。如果您能提供帮助,将不胜感激。
他们已经给了我一个C示例实现。
[DllImport("WiGroupDetect.dll", EntryPoint = "DetectTransactionCode", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
private static extern int DetectTransactionCode([MarshalAsAttribute(UnmanagedType.LPWStr)] StringBuilder strWITYPE, [MarshalAsAttribute(UnmanagedType.LPWStr)] StringBuilder strUID);
不确定这是否会改变我的 Delphi 实现。
cdecl
。 - LU RD