解决后再加100分!关于DLL的问题,请看下面代码。(在线等待,请高手帮忙) ( 积分: 100 )

  • 主题发起人 主题发起人 adibyu
  • 开始时间 开始时间
A

adibyu

Unregistered / Unconfirmed
GUEST, unregistred user!
library ReadMachineRec;

{ Important note about DLL memory management: ShareMem must be the
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. }

uses
SysUtils,
Classes,
Forms,
ADODB,
Windows,
ActiveX,
ReadMain in 'ReadMain.pas' {frmReadMain};

var
DLLApplication:TApplication;
DllScreen:TScreen;

Procedure ShowReadMachineRec(aApp:TApplication;DllScr:TScreen;InterfaceFile:Pchar;
ClearAllAfterRead:Boolean;DBCnn:TADOConnection);stdcall;
var
frmReadMain:TfrmReadMain;
begin
CoInitialize(Nil);
[red]//Application:=aApp;
//Screen:=DllScr;[/red] [blue]//为什么这两行不能加,否则退出DLL时就出错。 [/blue]
frmReadMain:=TfrmReadMain.Create(Application);
DllDBCnn:=TADOConnection.Create(Application);
DllDBCnn:=DBCnn;
frmReadMain.Aq_SaveRec.Connection :=DllDBCnn;
frmReadMain.Hide;
frmReadMain.ShowModal;
end;

procedure DLLUnloadProc(Reason: Integer);
begin
if Reason=DLL_PROCESS_DETACH then
begin
CoUnInitialize;
Application:=DLLApplication;
Screen := DLLScreen;
end;
end;

{$R *.res}

exports
ShowReadMachineRec;
begin
DLLApplication:=Application;
DLLScreen := Screen;
DLLProc := @DLLUnloadProc;
DLLUnloadProc(DLL_PROCESS_ATTACH);
end.
调用该DLL并关闭窗体frmReadMain后,出错:
Project F:/MyPro/Test.exe raised too many consecutive exceptions:......
请问这是为什么,如何解决?
 
library ReadMachineRec;

{ Important note about DLL memory management: ShareMem must be the
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. }

uses
SysUtils,
Classes,
Forms,
ADODB,
Windows,
ActiveX,
ReadMain in 'ReadMain.pas' {frmReadMain};

var
DLLApplication:TApplication;
DllScreen:TScreen;

Procedure ShowReadMachineRec(aApp:TApplication;DllScr:TScreen;InterfaceFile:Pchar;
ClearAllAfterRead:Boolean;DBCnn:TADOConnection);stdcall;
var
frmReadMain:TfrmReadMain;
begin
CoInitialize(Nil);
[red]//Application:=aApp;
//Screen:=DllScr;[/red] [blue]//为什么这两行不能加,否则退出DLL时就出错。 [/blue]
frmReadMain:=TfrmReadMain.Create(Application);
DllDBCnn:=TADOConnection.Create(Application);
DllDBCnn:=DBCnn;
frmReadMain.Aq_SaveRec.Connection :=DllDBCnn;
frmReadMain.Hide;
frmReadMain.ShowModal;
end;

procedure DLLUnloadProc(Reason: Integer);
begin
if Reason=DLL_PROCESS_DETACH then
begin
CoUnInitialize;
Application:=DLLApplication;
Screen := DLLScreen;
end;
end;

{$R *.res}

exports
ShowReadMachineRec;
begin
DLLApplication:=Application;
DLLScreen := Screen;
DLLProc := @DLLUnloadProc;
DLLUnloadProc(DLL_PROCESS_ATTACH);
end.
调用该DLL并关闭窗体frmReadMain后,出错:
Project F:/MyPro/Test.exe raised too many consecutive exceptions:......
请问这是为什么,如何解决?
 
关闭程序前释放DLL了么?
 
有释放呀,代码如下:
type
ReadRecDll=Procedure (aApp:TApplication;DllScr:TScreen;InterfaceFile:Pchar;
ClearAllAfterRead:Boolean;DBCnn:TADOConnection);stdcall;
var
DllHandle:THandle;
Dllfarproc:Tfarproc;
begin
With Aq_Detail do
begin
DllHandle:=LoadLibrary('ReadMachineRec.dll');
if DllHandle>32 then
try
Dllfarproc:=GetProcAddress(DllHandle,'ShowReadMachineRec');
if DllfarProc<>Nil then
ReadRecDll(Dllfarproc)(Application,Screen,Pchar(FieldByName('DllFilePath').AsString),FieldByName.('DelAfterReaded').AsBoolean,DllDBCnn);
finally
freelibrary(DllHandle);
end;
end;
end;
 
Application:=DLLApplication;
Screen:=DllScreen;
 
to bbscom
你的意思是删除这两行吗?如果是这样的意思的话,那我也试过,不行,再说,这两行也是应该要的吧。
 
传 THandle
Application.handle:=AppHandle;
 

Similar threads

I
回复
0
查看
641
import
I
I
回复
0
查看
754
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
2K
import
I
I
回复
0
查看
3K
import
I
后退
顶部