procedure TForm1.BitBtn5Click(Sender: TObject);
var
iret:boolean;
libhandle:thandle;
begin
libhandle:=loadlibrary('smeidll.dll');
iret:=ifinitinterface(3,1,'ip,port,5000');
if iret then
messagedlg('系统初始化成功!',mtInformation,[mbOK],0)
else messagedlg('系统初始化失败!请再试!',mtWarning,[mbCancel],0);
var
iret:boolean;
libhandle:thandle;
begin
libhandle:=loadlibrary('smeidll.dll');
iret:=ifinitinterface(3,1,'ip,port,5000');
if iret then
messagedlg('系统初始化成功!',mtInformation,[mbOK],0)
else messagedlg('系统初始化失败!请再试!',mtWarning,[mbCancel],0);
解决方案 »
- 请问怎么改变Tpopupmenu的背景色?
- 请教大家帮忙解决个问题,小弟在这里先谢过了!!!!!!!
- 菜鸟问题 FastReport3中怎么打印不了? 在线等~~~~急 急 急
- 3/19/04 10:32:29 AM 这样的DOS时间格式如何转换成yyyy-MM-dd HH:mm:ss的时间格式
- listbox问题
- 为什么MessageBox出来的消息框会不在所有窗体最前面?
- 请问打包过后生成为*.edl文件,是用什么打包了呢?
- 有誰用过INSTALLSHIELD3.03?
- 关于form 小的问题
- 用QuickRep作报表时总计与小计的显示
- 在Delphi里如何知道有没有产生内存泄露?
- 哪有ADO的补丁?
ifinitinterface 是你的DLL里的函数吗? 动态调用DLL函数不是这样用的! 要先定义:Type
Tifinitinterface=function(A:integer;B:integer;C:string);var
Myifinitinterface:Tifinitinterface;//Function
var
iret:boolean;
libhandle:thandle;
begin
libhandle:= LoadLibrary('smeidll.dll');
if libhandle>= 32 then
Begin
@Myifinitinterface:= GetProcAddress( libhandle, 'ifinitinterface');
If @Myifinitinterface<> nil Then {or If Assigned(Myifinitinterface) then }
Begin
Myifinitinterface(3,1,'ip,port,5000');
FreeLibrary(libhandle);
end;
end;
end;
如果解决了,就加点分,把帖子结了吧! 若还有能帮忙的问题,可以 Email: [email protected].
Tifinitinterface=function(A:integer;B:integer;C:string);阿明大哥,程序提示以上这句有问题,你看看吧!
上面好象有点小错!Type
Tifinitinterface=function(A:integer;B:integer;C:string):Boolean; //少返回值 //具体的形式要看你原来函数的定义
实际情况我看不到! 找段文章给你!10.DLL (动态库}
10.1 DLL 特徵
project 使用之单元是采静态连结(Statically Linked),而DLLs 采动态连结
(Dynamically Linked),故Projectl 中并包含DDLs之拷贝
DLLs 可用任何遵守windows DLL 之开发工具来开发或使用,适合多种开发工具
同时开发环境
10.2 DLL 使用
(1) 藉由名称(循序寻找)
Procedure ImportByName; External 'TestLib.dll';
(2) 藉由重新名称
Procedure ImportByNewName;
External 'TestLib.dll' name 'ImportByName';
(3) 藉由序号(找到程式的最快方法)
Procedure ImportByOrdName;
External 'TestLib.dll' Index 1;
(4) Windows Api 之呼叫
Function MessageBox( Hwnd: Integer ; Text,Caption:Pchr
Flags:Integer):Integer;Stdcall;
External 'User32.dll' Name 'MessageBox';
(5)动态库之输入程式单元
(例-1):Delphi 之开发环境中之 uses windows
(例-2):
unit DateTime;{动态库之输入程式单元}
interface
type
TTimeRec = Record
ss : integer;
mi : Integer;
hh : Integer;
end;
type
TDateRec = Record
yy:Integer;
mm:Integer;
dd:Integer;
end;
Procedure SetTime(Var Time:TTimeRec);
Procedure GetTime(Var Time:TTimeRec);
Procedure SetDate(Var Date:TDateRec);
Procedure GetDate(Var Date:TDateRec);
Implementation
Procedure SetTime; External 'DATETIME' index 1;
Procedure GetTime; External 'DATETIME' index 2;
Procedure SetDate; External 'DATETIME' index 3;
Procedure GetDate; External 'DATETIME' index 4;
end;
------------------------------------------------------
program ShowTime; {呼叫程式}
uses WinCrt , DateTime;
var
Time : TtimeRec;
begin
GetTime(Time);
With Time Do
WriteLn( 'Time is',hh,':',mi,':',ss);
end;
-----------------------------------------------------
(6)DDLs 之动态使用
program ShowTime;
uses WinProcs , WinTypesWinCrt;
type
TTimeRec = Record
ss : integer;
mi : Integer;
hh : Integer;
end;
TGETTime = Procedure( var Time : TTimeRec );
Var
Time : TTimeRec;
Handle : THandle;
GetTime : TGetTime;
Begin
Handle := LoadLibrary('DATETIME.DLL');
if Handle >= 32 then
Begin
@GetTime := GetProcAddress( Handle , 'GETTIME' );
If @GetTime <> nil Then {or If Assigned(GetTime) then }
Begin
GetTime(Time)
With Time do
WriteLn('Time is ',hh,':',mi,':',ss);
end;
FreeLibrary(handle);
end;
end.
10.3 DDLs 之撰写
10.3.1 例子
library minmax;
function Min( X , Y : Integer ) : Integer;
StdCall;
{避免非Delphi之程式呼叫,没有支援 register 呼叫惯例(内定值)}
Begin
If X < Y Then Min := X
else Min := Y;
end;
function Max( X , Y : Integer ) : Integer;StdCall;
Begin
If X > Y Then Max := X
else Max := Y;
end;
exports
Min index 1 name Min Resident;
Max index 2 name Max Resident;
Begin
end.
我这样都能编译通过,你比较比较(就一个Form,一个Button):unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Tifinitinterface=function(A:integer;B:integer;C:string):Boolean;var
Form1: TForm1;
Myifinitinterface:Tifinitinterface;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
//Function
var
iret:boolean;
libhandle:thandle;
begin
libhandle:= LoadLibrary('smeidll.dll');
if libhandle>= 32 then
Begin
@Myifinitinterface:= GetProcAddress( libhandle, 'ifinitinterface');
If @Myifinitinterface<> nil Then {or If Assigned(Myifinitinterface) then }
Begin
Myifinitinterface(3,1,'ip,port,5000');
FreeLibrary(libhandle);
end;
end;
end;
end.
只要是标准的DLL输出,应该没问题,要注意的是数据类型的匹配问题。比如,使用这些DLL的字符串参数时应使用widestring、Pchar、PwideChar、OleString等类型。直接用string类型会带来许多麻烦。又如,在标准的自动化对象使用longint参数时,Delphi中应使用const i:integer,而当其使用*longint时,Delphi中使用var i:integer等等。
还有你对于用DELPHI编通信程序,有什么好的建议吗,能告诉我吗
libhandle:= LoadLibrary('smeidll.dll');
if libhandle>= 32 then
Begin
@Myifinitinterface:= GetProcAddress( libhandle, 'ifinitinterface');
addr:=@myifinitinterface;
If addr<> nil Then
后,addr总是为nil啊,能告诉我这其中的原因吗?
能不能把你手头的东西都发过来?DLL文件(若有源码也附上吧)及说明文档、你的调用程序代码,我调一调试试。