FreeLibrary问题,高手请进! 我怀疑FreeLibrary这个函数有BUG,因外我在做程序时经常碰到这样的错误,一使用FreeLibrary来释放DLL就出错,而注释掉这条语句,一切正常! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 但不释放系统资源也不是办法呀,FreeLibrary在VC中也经常用,好像不存在BUG,Windows系统中Dll这样应用也比较常见,没有问题呀? 放在这里:initialization LoadLibrary(...);finalization FreeLibrary(...); borlandor可以详细说明一下吗,不胜感谢! //Please try it!Var DLLHandle: THandle;implementionprocedure TForm1.AnyYourProcedure;begin {You can use DLLHandle here}end;......initialization DLLHandle := LoadLibrary(...);finalization FreeLibrary(DLLHandle);end. 问题出在dll中再调用Dll,不论对Lib1.dll的FreeLibrary操作在何处执行,或干脆注释掉,但关闭程序时就会出错! 这样可以的呀!我曾经用过的,而且在第一个DLL中包括了线程。不过只是显式调用了第二个DLL。 我第二个Dll类似vc中的函数库,里面都是公用函数,不想显示调用!能否象引用Windows Api 一样调用它? 你先用EXE隐式调用第二个DLL试一试。 ///////////完整的例子///////////unit Main;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Edit2: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;// function GetInteger(I:Integer): Integer;stdcall;external 'DLLOne.dll';// function GetDouble(F:Double): Double;stdcall;external 'DLLOne.dll'; TGetDouble = function (F:Double): Double; stdcall;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var D: Double; DLLHandle: THandle; Func: TGetDouble;begin DLLHandle := LoadLibrary('DLLOne.dll'); try @Func := GetProcAddress(DLLHandle, 'GetDouble'); //Edit1.Text := IntToStr(GetInteger(2)); //D := GetDouble(2.2); if Assigned(@Func) then begin D := Func(2.2); Edit2.Text := FloatToStr(D); end; finally FreeLibrary(DLLHandle); end;end;end.library DLLOne;uses SysUtils, Classes;{$R *.res} function GetDoubleExt(F:Double): Double;stdcall;external 'DLLTwo.dll'; function GetInt(I:Integer): Integer;stdcall;external 'DLLTwo.dll'; function GetInteger(I:Integer): Integer;stdcall; begin Result := GetInt(I); end; function GetDouble(D:Double): Double;stdcall; begin Result := GetDoubleExt(D); end;exports GetInteger, GetDouble;beginend.library DLLTwo;uses SysUtils, Classes;{$R *.res} function GetDoubleExt(D:Double):Double ;stdcall; begin Result := D; end; function GetInt(I:Integer): Integer;stdcall; begin Result := I; end;exports GetDoubleExt, GetInt;beginend. 解决了,问题不在Freelibrary,而是对ShareMem单元的引用上,多谢 borlandor、 liusp 的热心帮助! 在Delphi应用Dll还要注意些什么?需要写入口函数DLLMain吗?望指教一二! 数据库validation error for column XX,value "***null***" 谁用过TwwDBLookupComboDlg控件? 我想用Delphi写一个邮件收发组件的DLL,请教一些。 请问在客户端不装delphi如何快速安装配置好bde? 如何在图象上用鼠标拉框? DELPHI群 求购DRP分销管理系统Delphi+SQLSERVER源码..... 付钱求一段程序 该发一个怎样的消息让另一个窗口或者应用程序最大化呢? 高分征求系统规划方案!!!! 有没有办法让表中的记录上下移动 Delphi图片保存及显示问题???
LoadLibrary(...);
finalization
FreeLibrary(...);
begin
{You can use DLLHandle here}
end;......
initialization
DLLHandle := LoadLibrary(...);finalization
FreeLibrary(DLLHandle);
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;// function GetInteger(I:Integer): Integer;stdcall;external 'DLLOne.dll';
// function GetDouble(F:Double): Double;stdcall;external 'DLLOne.dll'; TGetDouble = function (F:Double): Double; stdcall;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var D: Double;
DLLHandle: THandle;
Func: TGetDouble;
begin DLLHandle := LoadLibrary('DLLOne.dll');
try
@Func := GetProcAddress(DLLHandle, 'GetDouble'); //Edit1.Text := IntToStr(GetInteger(2));
//D := GetDouble(2.2);
if Assigned(@Func) then
begin
D := Func(2.2);
Edit2.Text := FloatToStr(D);
end; finally
FreeLibrary(DLLHandle);
end;
end;end.
library DLLOne;uses
SysUtils,
Classes;{$R *.res} function GetDoubleExt(F:Double): Double;stdcall;external 'DLLTwo.dll';
function GetInt(I:Integer): Integer;stdcall;external 'DLLTwo.dll'; function GetInteger(I:Integer): Integer;stdcall;
begin
Result := GetInt(I);
end; function GetDouble(D:Double): Double;stdcall;
begin
Result := GetDoubleExt(D);
end;exports
GetInteger,
GetDouble;begin
end.
library DLLTwo;uses
SysUtils,
Classes;{$R *.res}
function GetDoubleExt(D:Double):Double ;stdcall;
begin
Result := D;
end;
function GetInt(I:Integer): Integer;stdcall;
begin
Result := I;
end;exports
GetDoubleExt,
GetInt;begin
end.