请问vb->delphi中的字符串用pchar还是string,为什么我下面的vb转换delphi代码不行?

syswer 2001-12-27 05:18:34
Declare Function write_card Lib "STICCW32.DLL" (ByVal hiCC%, ByVal zone%, ByVal addr%, ByVal data_len%, ByVal dat$) As Integer

Private Sub Command8_Click()
Dim sTmp As String
sTmp = Trim(Text7.Text)
nstatus% = write_card(nhiCC, 0, 32, 10, sTmp)
If nstatus = 0 Then
MsgBox "OK!"
Else
MsgBox "error!"
End If
end sub
出错的原因在于不知sTmp变量为什么类型?以及dll文件函数中的dat为何类型?
...全文
142 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
甜而不腻 2001-12-27
  • 打赏
  • 举报
回复
傻!
syswer 2001-12-27
  • 打赏
  • 举报
回复
function write_card ( hiCC :integer; zone : integer; addr : integer;
data_len : integer; dat : pchar) : Integer; stdCall;external 'STICCW32.DLL';
procedure TForm1.Button6Click(Sender: TObject);
var
datt : pchar;
stay : integer;
len : integer;
begin
stay:=strtoint(edit3.Text );
len:=strtoint(edit4.Text );
datt:=pchar(trim(edit5.Text));
if stay>=32 then
begin
if len<20 then
begin
nstatus := write_card(nhicc,0,32,10,datt);
if nstatus=0 then
edit1.Text :=datt
else edit1.text :=inttostr ( nstatus );
end;
end;
end;

可是发现edit1.text显示的字符串都变成乱码了,请问我该怎么办?
王集鹄 2001-12-27
  • 打赏
  • 举报
回复
function read_card(hiCC: Word; zone: Word; addr: Word; data_len: Word; dat: PChar): Integer; stdcall; external 'STICCW32.DLL';
//Declare Function write_card Lib "STICCW32.DLL" (ByVal hiCC%, ByVal zone%, ByVal addr%, ByVal data_len%, ByVal dat$) As Integer
function write_card(hiCC: Word; zone: Word; addr: Word; data_len: Word; dat: PChar): Integer; stdcall; external 'STICCW32.DLL';
//Declare Function write_card Lib "STICCW32.DLL" (ByVal hiCC%, ByVal zone%, ByVal addr%, ByVal data_len%, ByVal dat$) As Integer

procedure TForm1.Button1Click(Sender: TObject);
//Private Sub Command8_Click()
var
sTmp: PChar;
nstatus: Integer;
nhiCC: Integer;
begin
sTmp := PChar(Trim(Edit1.Text));
nstatus := write_card(nhiCC, 0, 32, 10, sTmp);
If nstatus = 0 Then
ShowMessage('OK!')
Else ShowMessage('error!')
end;

chrisz 2001-12-27
  • 打赏
  • 举报
回复
PChar(String类型)即可为PChar
nbwzw 2001-12-27
  • 打赏
  • 举报
回复
动态连接库一般都是用C++写的,主要是指针类型应该用PChar类型
syswer 2001-12-27
  • 打赏
  • 举报
回复
zswang(伴水)(被黑中):你好,
请你再帮我把上面的代码在转换一下好吗,谢谢,我改的中编译通不过。
王集鹄 2001-12-27
  • 打赏
  • 举报
回复
动态连接库里的字符串一般都是PChar

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧