DLL的定义中有一个函数
function test(var pst:pchar):integer;stdcall
var str:string ;
begin
str:='ILOVEYOU';
pst:=Pchar(str);//强制转换
showmessage(pst);//显示真确。为ILOVEYOU
result:=1;
end;调用如下
procedure TForm1.Button9Click(Sender: TObject);
var a:pchar;
z:integer;
begin
a:=allocmem(8);
z:=test(a);
showmessage(a);
end;结果显示的是乱码 两次显示的不一样请 问是不是我写dll错了,还是调用有问题。
function test(var pst:pchar):integer;stdcall
var str:string ;
begin
str:='ILOVEYOU';
pst:=Pchar(str);//强制转换
showmessage(pst);//显示真确。为ILOVEYOU
result:=1;
end;调用如下
procedure TForm1.Button9Click(Sender: TObject);
var a:pchar;
z:integer;
begin
a:=allocmem(8);
z:=test(a);
showmessage(a);
end;结果显示的是乱码 两次显示的不一样请 问是不是我写dll错了,还是调用有问题。
解决方案 »
- 帮我找找这段话的错误,错误提示S没有参数默认值
- 如何列出所有符合条件的项目?
- delphi 登陆窗口的问题
- 用ComponentCount出现的错误!!
- 怎样把文件中的数据一行行读出来?
- 朋友们,我这里有Delphi控制autocad的OLE特性、方法等操作手册,谁要?
- 为何在COM中使用Clientsocket控件时总出错?
- menliwxj, 来接100分。
- 高手们帮忙解决调用应用服务器程序死机问题,有高分相送!
- 请问如何在delphi中实现超链!(菜鸟问题,不过给分)
- 关于delphi的quintf.dll接口库和自带的installshield express制作打包文件问题
- 欲删除多个记录时出现错误:“当前提供程序不支持从单一持行返回多个记录集”,怎么办?
还是老问题是传值还是传址的问题啊
dll中当然可以改pst:=Pchar(str);
不过你赋值后pst已经不等于a拉
真个过程你没有给a赋值当然是乱码
dll中不要赋值用
strpcopy(pst,str);
这样才能传回来你的程序就算不是dll,而是再一个exe中也是一样啊
基本功不扎实,尤其是指针的操作
function test(var pst:pchar):integer;stdcall
var str:string ;
begin
str:='ILOVEYOU';
strpcopy(pst,str);
showmessage(pst);//显示真确。为ILOVEYOU
result:=1;
end;
在vb里调用如下
Declare Function test Lib "ICEnginer.dll" (ByVal pst As String) As Integer
Dim b As String
Dim z As Integer
b = Space(255)
z = test(b)
MsgBox b
End Sub
结果提示错误
如果 在dll里把 strPcopy(pst,str) 改成pst:=Pchar(str);则出现乱码
var str:string ;
begin
str:='ILOVEYOU';
strpcopy(pst,str);
//pst:=Pchar(str);//强制转换
showmessage(strpas(pst));//显示真确。为ILOVEYOU
result:=1;
end;