R
rikhong
Unregistered / Unconfirmed
GUEST, unregistred user!
为什么我VB调用DELPHI做的DLL,传过去的参数都是乱吗?具体看以下代码
我用参数返回的方式返回一串PCHAR字符,在DELPHI下很正常,但VB连传过去的参数都变成乱码
DELPHI DLL:
procedure SetGunState(Despensor_nochar;Despensor_statechar;protocolchar;var ResultCmdchar);stdcall;
var StrCmd:string;
value:integer;
begin
SHOWMESSAGE(Despensor_no+' '+Despensor_state+' '+Despensor_state); //VB下到这一句发现所有参数都是乱码
value:=StrToInt(Despensor_no);
if protocol = protocol_HS then
begin
StrCmd:=#$41#$42#$43#$61#$62;
end;
if protocol = protocol_HS1 then
begin
StrCmd:=(#$9B+chr(value)+#$02#$A2);
end;
if protocol = protocol_HS2 then
begin
StrCmd:=(#$9B+chr(value)+#$02#$A2);
end;
ResultCmd:=pchar(StrCmd);
ShowMessage(ResultCmd+StrCmd)
end;
VB 调用代码:
Public Declare Sub SetGunState Lib "C:/HScom.dll" (Despensor_no As String, Despensor_state As String, protocol As String, ByRef CMD As String)
Private Sub Command1_Click()
Dim s As String
s = Space(26)
Module1.SetGunState "2", "1", "AA", s
Text1.Text = s
' Module1.Gets
End Sub
我用参数返回的方式返回一串PCHAR字符,在DELPHI下很正常,但VB连传过去的参数都变成乱码
DELPHI DLL:
procedure SetGunState(Despensor_nochar;Despensor_statechar;protocolchar;var ResultCmdchar);stdcall;
var StrCmd:string;
value:integer;
begin
SHOWMESSAGE(Despensor_no+' '+Despensor_state+' '+Despensor_state); //VB下到这一句发现所有参数都是乱码
value:=StrToInt(Despensor_no);
if protocol = protocol_HS then
begin
StrCmd:=#$41#$42#$43#$61#$62;
end;
if protocol = protocol_HS1 then
begin
StrCmd:=(#$9B+chr(value)+#$02#$A2);
end;
if protocol = protocol_HS2 then
begin
StrCmd:=(#$9B+chr(value)+#$02#$A2);
end;
ResultCmd:=pchar(StrCmd);
ShowMessage(ResultCmd+StrCmd)
end;
VB 调用代码:
Public Declare Sub SetGunState Lib "C:/HScom.dll" (Despensor_no As String, Despensor_state As String, protocol As String, ByRef CMD As String)
Private Sub Command1_Click()
Dim s As String
s = Space(26)
Module1.SetGunState "2", "1", "AA", s
Text1.Text = s
' Module1.Gets
End Sub