主题:各位 大侠 关于调用DLL的问题(高份请教)
克里斯
[专家分:0] 发布于 2006-11-09 11:44:00
我在调用我写的DLL时出错了出的是英文的错
function Dll1(g:string):string;stdcall;
begin
Result:=g;
end;
exports
Dll1;
然后 我在我的主程序调用它
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
function Dll1(g:string):string;stdcall;
external 'Dll.dll';
procedure TForm1.Button2Click(Sender: TObject);
begin
// Edit2.Text:=Dll1('w');
showmessage(Dll1('w'));
end;
请问 哪地方出错啊
回复列表 (共6个回复)
沙发
zwt [专家分:1230] 发布于 2006-11-09 16:15:00
function Dll1(g:string):string;stdcall;
begin
Result:=g;
end;
exports
Dll1;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
function Dll1(g:string):string;stdcall;
external '动态链接库的名称.dll';
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage(Dll1('w'));
end;
板凳
克里斯 [专家分:0] 发布于 2006-11-09 18:04:00
和我写的一样啊 我没看出来哪地方不一样啊
3 楼
wealthy [专家分:1840] 发布于 2006-11-09 20:29:00
是否错在这里:(多个1)
function Dll1(g:string):string;stdcall;
external 'Dll1.dll';
而不是(少个1)
function Dll1(g:string):string;stdcall;
external 'Dll.dll';
4 楼
zwt [专家分:1230] 发布于 2006-11-10 09:57:00
我调试可以,把错误提示贴出来,大家一块分析!
5 楼
dodolon [专家分:400] 发布于 2006-11-11 16:40:00
Delphi DLL向导的重要说明:
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
使用string类型的返回值或参数时,需要相应单元(包括工程单元)的USES中加入SHAREMEM单元,而且要是第一个。若不使用SHAREMEM,则参数或返回值要用PChar或短字符中类型,如String[200]。
例: procedure GetDllString(const ID:integer; ReturnStr: PChar);
6 楼
克里斯 [专家分:0] 发布于 2006-11-13 11:21:00
谢谢各位 非常感谢真的 请留下各位的qq号好吗
我来回复