动态调用一个DLL时发生错误
JB7 2005-07-30 10:25:48
动态调用一个DLL时发生错误。 ,程序没有任何提示,自动中止,
DLL的源代码如下:
library P0092;
{ 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
ShareMem,
SysUtils,
COMSERV,
adodb,
db,
QForms,
QGraphics,
variants,
Classes,
modDeclare in '..\..\Module\modDeclare.pas',
W0092A in 'W0092A.pas' {FmW0092A};
{$E dll}
{$R *.res}
Function GetUserID( para:DllParaLine):pChar ;stdcall;
VAR
tmpForm:TFmW0092A;
Begin
tmpForm:=TFmW0092A.Create(nil);
if para.SW_SHOW =0 then
tmpForm.showMODAL
else
tmpForm.showmodal;
Result:='3';
End;
Exports GetUserID Name 'GetUserID' ;
begin
DllRegisterServer();
end.
调用代码如下:
Function ExecDllItem(DllName:pchar;FunName:pChar; para:DllParaLine):string;
Type
THandle = Integer;
tff=Function (para:DllParaLine):pchar;stdcall;
var
tf:tff;
Th:Thandle; // 句柄
tmpPara:DllParaLine;
Tp:TFarProc; //内部地址
Begin
with tmpPara do
Begin
gCn:=gCn;
rCn:=rCn;
UserID:=para.UserID;
UserName:=para.UserName;
strFunName:=para.strFunName;
strPara1:=para.strPara1;
strPara2:=para.strPara2;
strPara3:=para.strPara3;
strPara4:=para.strPara4;
strPara5:=para.strPara5;
curPara1:=para.curPara1;
curPara2:=para.curPara2;
curPara3:=para.curPara3;
curPara4:=para.curPara4;
curPara5:=para.curPara5;
SW_SHOW :=0;
End;
//开始装载函数
Th:=LoadLibrary(dllName);
if Th>0 then
Begin
//获取入口地址
@Tf:=GetProcAddress(Th,FunName);
if @tf<> nil then
Begin
Result:=tf(tmpPara);
End
Else
Begin
MessageDlg ('缺少函数'+FunName+',请与系统管理员联系!',mtError,[MBOK],0);
End;
End
Else
Begin
MessageDlg (dllName+'未找到,请与系统管理员联系!',mtError,[MBOK],0);
End;
FreeLibrary(Th); {释放DLL}
End;