■初学者请教,静态调用Dll,为什么总报错?
Dll我是这么写的-----------------
{$R *.res}
function ABCC(aaa:string):string;stdcall;
begin
result:=aaa+'***';
end;
exports
ABCC;
begin
end.
调用语句我是这么写的---------------
implementation
{$R *.dfm}
function ABCC(aaa:string):string;stdcall;external 'Project1.dll';
procedure TForm1.Button3Click(Sender: TObject);
begin
showmessage(ABCC(edit1.Text));
end;
-------------------------
问题是调用没有问题,但是每次弹出对话框说:
Invalid pointer operation.
问题点数:20、回复次数:5Top
1 楼sephil(NAILY Soft 【哈里波特大】)回复于 2005-03-14 10:57:32 得分 0
string改成PCharTop
2 楼aus(天兵)回复于 2005-03-14 10:58:03 得分 0
不要用String
最好用PChar之类的指针类型变量Top
3 楼pengxuan(网虫先生)回复于 2005-03-14 11:04:44 得分 0
跟String没有关系,D报什么错。Top
4 楼DDGG(叮叮当当)回复于 2005-03-14 11:50:18 得分 20
在你新建一个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类型作为函数参数的话,就要在DLL里和调用DLL的应用程序里都引用ShareMem单元,而且要写在第一个(紧跟着uses)。
uses ShareMem, ...
要注意的是,在调用DLL的应用程序里引用ShareMem单元时,不是写在当前窗体的单元里,而是dpr项目文件里(选择Project->View Source菜单)。Top
5 楼dyh506(浪)回复于 2005-03-14 11:55:24 得分 0
string是delphi里面特有的数据类型,做dll时要使用就如楼上所说的要用sharemem单元,不然就用pchar
或字符数据Top




