D
discovered
Unregistered / Unconfirmed
GUEST, unregistred user!
大概是这样的
我写了一个dll,dll里封装了一个form,form 里要是不放ado的控件就不会出错,一放就出错...
以下这个是dll
-----------------------------
library Pdll1;
uses
SysUtils,
Classes,
Udll1 in 'Udll1.pas' {Form1},
// Udata in 'Udata.pas' {DataModule1: TDataModule};
{$R *.res}
exports
ShowPerSN ;//2.函数输出口定义
begin
end.
---------------以下是dll中加的form
unit Udll1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL; StdCall;
implementation
{$R *.dfm}
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL;
var
Form1: TForm1; //定义窗体类(上面的放到了此处)
begin
//拷贝应用程式句柄给DLL的应有程式对象
Application.Handle := AHandle;
Form1 := TForm1.Create(Application);//创建控件TForm
try
Form1.Caption := ACaption;
Form1.ShowModal;//显示此Form
Result := False; //反回成功值
finally
Form1.Free;
end;
end;
---------------------以下是主程序的调用.
unit Uexe;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
type
TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall;
EDLLLoadError = class(Exception);
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var //按钮的调用事件:调用过程
LibHandle: THandle;
ShowPerSN: TShowPerSN;
begin
Application.Title:='人力资源管理系统DLL文件测试程式';
{ Attempt to load the DLL 尝试装入DLL文件}
LibHandle := LoadLibrary('Pdll1.dll');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('无法成功装入Pdll1.dll');
@ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN');
if not (@ShowPerSN = nil) then
ShowPerSN(Application.Handle, '人事资料管理')//呼叫出窗体
else
RaiseLastwin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;
只要我在dll中的form加入ado的控件,主程序调用就会出错..
错误提示为:
access violation at address 004030DE in module 'Pexe.exe',read of address 012E3EB8
end.
end.
我写了一个dll,dll里封装了一个form,form 里要是不放ado的控件就不会出错,一放就出错...
以下这个是dll
-----------------------------
library Pdll1;
uses
SysUtils,
Classes,
Udll1 in 'Udll1.pas' {Form1},
// Udata in 'Udata.pas' {DataModule1: TDataModule};
{$R *.res}
exports
ShowPerSN ;//2.函数输出口定义
begin
end.
---------------以下是dll中加的form
unit Udll1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL; StdCall;
implementation
{$R *.dfm}
function ShowPerSN(AHandle: THandle; ACaption: String):BOOL;
var
Form1: TForm1; //定义窗体类(上面的放到了此处)
begin
//拷贝应用程式句柄给DLL的应有程式对象
Application.Handle := AHandle;
Form1 := TForm1.Create(Application);//创建控件TForm
try
Form1.Caption := ACaption;
Form1.ShowModal;//显示此Form
Result := False; //反回成功值
finally
Form1.Free;
end;
end;
---------------------以下是主程序的调用.
unit Uexe;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
type
TShowPerSN = function (AHandle: THandle; ACaption: String): BOOL; StdCall;
EDLLLoadError = class(Exception);
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var //按钮的调用事件:调用过程
LibHandle: THandle;
ShowPerSN: TShowPerSN;
begin
Application.Title:='人力资源管理系统DLL文件测试程式';
{ Attempt to load the DLL 尝试装入DLL文件}
LibHandle := LoadLibrary('Pdll1.dll');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('无法成功装入Pdll1.dll');
@ShowPerSN := GetProcAddress(LibHandle, 'ShowPerSN');
if not (@ShowPerSN = nil) then
ShowPerSN(Application.Handle, '人事资料管理')//呼叫出窗体
else
RaiseLastwin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;
只要我在dll中的form加入ado的控件,主程序调用就会出错..
错误提示为:
access violation at address 004030DE in module 'Pexe.exe',read of address 012E3EB8
end.
end.