报错是在主程序退出时,错误信息如下:
xxx.exe raised too many consecutive exceptions:'Access violation at 0x01193458:read of address 0x00951934'代码如下:
主程序:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure LoadUIDLL(ProgName:string);
public
{ Public declarations }
end;
TShowUIForm = procedure (AHandle: TApplication;ConStr:String;
Userid:String;Lug:string;sc:TScreen;FrmName:string);stdcall;
var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.LoadUIDLL(ProgName:string);
var
LibHandle: HWND;
ShowUIForm: TShowUIForm;
begin
LibHandle := LoadLibrary(Pchar(ProgName+'.dll'));
if LibHandle < 32 then
begin
Messagedlg('test1',mterror,[mbok],0);
exit;
end;
@ShowUIForm := GetProcAddress(LibHandle,'ShowUIForm');
if @ShowUIForm <> nil then
try
ShowUIForm(Application,'13123','13123','1',
Screen,'Form1');
except
raise Exception.Create('test error');
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
LoadUIDLL('Project2');
end;end.
DLL程序:
library Project2;uses
shareMem,
Windows,
Graphics,
Messages,
Forms,
Controls,
SysUtils,
Classes,
Dialogs,
Unit2 in 'Unit2.pas' {Form1};var
DLLApp:TApplication;
DLLScreen:TScreen;
TheForm:TForm;
TheClass:TPersistentClass;
{$R *.res}
procedure ShowUIForm(AHandle: TApplication;
ConStr:String;
Userid:String;
Lug:string;
sc:TScreen;
FrmName:string
);stdcall;
begin
Application := AHandle;
Screen:=sc;
RegisterClass(TForm1);
theclass:=GetClass('T'+FrmName);
if (theclass<>nil) and theclass.InheritsFrom(TForm) then
begin
theForm:=TForm(theclass.Create).Create(nil);
theForm.ShowModal;
end;
End;procedure DLLUnloadProc(Reason:Integer);register;
begin
if Reason = DLL_PROCESS_DETACH THEN
begin
Application := DLLApp;
screen:=DLLScreen;
FreeAndNil(theForm);
SendMessage(Application.Handle,WM_CLOSE,0,0);
FreeLibrary(Application.Handle);
end;
end;exports
ShowUIForm;begin
DLLApp:=Application;
DLLScreen:=Screen;
DLLProc:=@DLLUnloadProc;
end.
xxx.exe raised too many consecutive exceptions:'Access violation at 0x01193458:read of address 0x00951934'代码如下:
主程序:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure LoadUIDLL(ProgName:string);
public
{ Public declarations }
end;
TShowUIForm = procedure (AHandle: TApplication;ConStr:String;
Userid:String;Lug:string;sc:TScreen;FrmName:string);stdcall;
var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.LoadUIDLL(ProgName:string);
var
LibHandle: HWND;
ShowUIForm: TShowUIForm;
begin
LibHandle := LoadLibrary(Pchar(ProgName+'.dll'));
if LibHandle < 32 then
begin
Messagedlg('test1',mterror,[mbok],0);
exit;
end;
@ShowUIForm := GetProcAddress(LibHandle,'ShowUIForm');
if @ShowUIForm <> nil then
try
ShowUIForm(Application,'13123','13123','1',
Screen,'Form1');
except
raise Exception.Create('test error');
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
LoadUIDLL('Project2');
end;end.
DLL程序:
library Project2;uses
shareMem,
Windows,
Graphics,
Messages,
Forms,
Controls,
SysUtils,
Classes,
Dialogs,
Unit2 in 'Unit2.pas' {Form1};var
DLLApp:TApplication;
DLLScreen:TScreen;
TheForm:TForm;
TheClass:TPersistentClass;
{$R *.res}
procedure ShowUIForm(AHandle: TApplication;
ConStr:String;
Userid:String;
Lug:string;
sc:TScreen;
FrmName:string
);stdcall;
begin
Application := AHandle;
Screen:=sc;
RegisterClass(TForm1);
theclass:=GetClass('T'+FrmName);
if (theclass<>nil) and theclass.InheritsFrom(TForm) then
begin
theForm:=TForm(theclass.Create).Create(nil);
theForm.ShowModal;
end;
End;procedure DLLUnloadProc(Reason:Integer);register;
begin
if Reason = DLL_PROCESS_DETACH THEN
begin
Application := DLLApp;
screen:=DLLScreen;
FreeAndNil(theForm);
SendMessage(Application.Handle,WM_CLOSE,0,0);
FreeLibrary(Application.Handle);
end;
end;exports
ShowUIForm;begin
DLLApp:=Application;
DLLScreen:=Screen;
DLLProc:=@DLLUnloadProc;
end.
解决方案 »
- Delphi中如何把A,B两表在一个DBGRID中显示,而更新时只更新A表?
- 急,请帮帮忙,关于DLL的问题
- 在memo控件中怎样获得每行的索引?
- 如何让dbgridEh显示出多行(即使datasource中无数据)
- 火急!!!!!关于Delphi7中TcpClient接收TcpServer数据的问题。
- 如何将pbyte指向的byte数据传递给byte数组或char等
- 谁知道如何读取硬盘的ID号?
- 让ie打开网页不显示图片,需修改注册表的哪一项?
- 有关speedbutton的背景色的问题??
- 有谁知道wingate4.3进入的用户名和密码
- TStringList 与 数组
- 深圳Delphi程序员待遇调查
应该注册一下再使用!rgsvr32命令