地
地质灾害
Unregistered / Unconfirmed
GUEST, unregistred user!
Dll代码如下:
library Security;
{ 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,
Windows,
Classes,
ComObj,
ActiveX,
ADOInt,
Interfaces in '../Units/Interfaces.pas',
SecTypes in '../Units/SecTypes.pas',
OriginADO in '../Units/OriginADO.pas';
{$R *.res}
var
OldDllProc:TDLLProc;
procedure DllEntryPoint(Reason:Integer);
const
CmdTimeOut=5000;
begin
case Reason of
DLL_PROCESS_ATTACH:
begin
CoInitialize(nil);
ADO_Cmd:=CreateComObject(CLASS_Command) as _Command;
ADO_Cmd.CommandTimeout:=CmdTimeOut;
ADO_RecSet:=CreateComObject(CLASS_Recordset) as _Recordset;
ADO_RecSet.CacheSize:=1000;
ADO_RecSet.LockType:=adLockOptimistic;
ADO_RecSet.CursorLocation:=adUseClient;
ADO_RecSet.CursorType:=adOpenStatic;
end;
DLL_PROCESS_DETACH:
begin
ADO_Cmd._Release;
ADO_RecSet._Release;
CoUninitialize;
DllProc:=OldDllProc;
end;
end;
end;
exports
SetConnection,
GetUsers;
begin
OldDllProc:=DllProc;
DllProc:=@DllEntryPoint;
DllEntryPoint(DLL_PROCESS_ATTACH);
end.
在DLL中创建ADO原生对象。在调用此Dll的程序退出后,出现Access Violation。导出的两个函数在Dll工程的其它单元中。把DllEntryPoint过程中创建COM和释放COM对像的代码去掉后不会出错。请高手解惑!
library Security;
{ 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,
Windows,
Classes,
ComObj,
ActiveX,
ADOInt,
Interfaces in '../Units/Interfaces.pas',
SecTypes in '../Units/SecTypes.pas',
OriginADO in '../Units/OriginADO.pas';
{$R *.res}
var
OldDllProc:TDLLProc;
procedure DllEntryPoint(Reason:Integer);
const
CmdTimeOut=5000;
begin
case Reason of
DLL_PROCESS_ATTACH:
begin
CoInitialize(nil);
ADO_Cmd:=CreateComObject(CLASS_Command) as _Command;
ADO_Cmd.CommandTimeout:=CmdTimeOut;
ADO_RecSet:=CreateComObject(CLASS_Recordset) as _Recordset;
ADO_RecSet.CacheSize:=1000;
ADO_RecSet.LockType:=adLockOptimistic;
ADO_RecSet.CursorLocation:=adUseClient;
ADO_RecSet.CursorType:=adOpenStatic;
end;
DLL_PROCESS_DETACH:
begin
ADO_Cmd._Release;
ADO_RecSet._Release;
CoUninitialize;
DllProc:=OldDllProc;
end;
end;
end;
exports
SetConnection,
GetUsers;
begin
OldDllProc:=DllProc;
DllProc:=@DllEntryPoint;
DllEntryPoint(DLL_PROCESS_ATTACH);
end.
在DLL中创建ADO原生对象。在调用此Dll的程序退出后,出现Access Violation。导出的两个函数在Dll工程的其它单元中。把DllEntryPoint过程中创建COM和释放COM对像的代码去掉后不会出错。请高手解惑!