unit useDll;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtDlgs;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
OpenDialog1: TOpenDialog;
Label1: TLabel;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure Button4Click(Sender: TObject); private
Th:Thandle;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1; procedure OpenWinsocket(
ServerIP:string;port:integer;sfileName:string);stdcall; external
'SentFile.dll' ;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
try
if OpenDialog1.Execute then
edit1.Text:=OpenDialog1.FileName;
except
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
{
if edit1.Text='' then
edit1.Text:= 'D:\ks.doc';
}
try
OpenWinsocket('192.168.1.1',1225,trim(edit1.Text));
except
end;end;
procedure TForm1.Button3Click(Sender: TObject);
type
TIntFunc=procedure(ServerIP:string;port:integer;sfileName:string);stdcall;
var
//Th:Thandle;
Tf:TIntFunc;
Tp:TFarProc;
s:bool;
begin
Th:=LoadLibrary('SentFile.dll'); //装载DLL
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('OpenWinsocket'));
if Tp<>nil then begin
Tf:=TIntFunc(Tp);
Tf('192.168.1.1',1225,trim(edit1.Text));
end
else
ShowMessage('函数没有找到');
finally
//FreeLibrary(Th); {释放DLL
end
else
ShowMessage('SentFile.dll没有找到');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
FreeLibrary(Th);
//Form1.Free;
//Form1:=nil;
action:=cafree;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
//Form1:=nil;
end;procedure TForm1.Button4Click(Sender: TObject);
begin
application.Terminate
end;end.
解决方案 »
- ADOQUERY模糊查询的sql语句应该怎写
- 如何在Delphi中使用ODAC(OraQuery\QraStordc)读写Oracle中Clob字段?
- 请问如何屏蔽form窗口的关闭按钮
- 如何查找相同的记录?
- 我想访问串行口,请大家给出个主意
- 毕业三年了,在北京工作也一年了,如今辞职两周了,还没找到工作,给点意见!!!
- DELPHI5在WINDOWS2000超级用户中安装完毕,如何使得其他用户也能用?(其它用户少了很多控件)
- 请问如何在dbgrid控件中 第3列=第2列×第1列
- 同盟们 帮帮忙!
- Help急急急急急!!!!!!怎样得到另外一个可执行文件里"Button"的句柄?
- 初级问题.
- 如何从baidu贴吧的cgi-bin/genimg中取验证码可用图片 idhttp、WebBrowser``或者随便什么控件都好```
ServerIP:string;port:integer;sfileName:string);stdcall; external
'SentFile.dll' ;
===============
如果要自己手工LoadLibrary,则把后面的external...去掉,手工管理。
问题在动态库内部,可能需要borlandmm.dll(类似,具体名称不记得),如果换不行就尽可能避免该错误
我一般在动态库中,不使用string等特有数据类型,避免该类问题,不再深究
procedure OpenWinsocket(
ServerIP:string;port:integer;sfileName:string);stdcall; external
'SentFile.dll' ;
所在的单元文件 OpenWinsocket(
有问题
ServerIP:string;port:integer;sfileName:string);stdcall; external
'SentFile.dll' ;
中 external 'SentFile.dll' ;有点多余了吧
ServerIP:string;port:integer;sfileName:string);stdcall; external
'SentFile.dll' ;这个dll是使用delphi编写的吗?如果是你修改一下你的dll将string类型修改成pchar类型,虽然uses ShareMem可能会解决这样的问题,但是还是不建议在dll中使用string类型
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. }每个 dll project 都会有这个提示。
1、如果用 LoadLibrary就不要以external方式声明函数;
2、尽量不使用delphi独有的类型