我用一个程序动态调用dll
LoadLibrary('..\dll\project2.dll');
时 出现错误 错误如下 :
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EApplicationError with message 'Fatal error: Cannot create application object in a shared object or library.'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
帮忙解决阿? 马上给分!
LoadLibrary('..\dll\project2.dll');
时 出现错误 错误如下 :
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EApplicationError with message 'Fatal error: Cannot create application object in a shared object or library.'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
帮忙解决阿? 马上给分!
解决方案 »
- 大家来YY,如果windows是中国人开发,想象哈API会怎么取名字?
- 为什么有时候出错,有时候不出错啊?大家帮我看一下(关于Excel)
- 我做了一个nt服务,用TADOConnection连接数据库,如果在控件的ConnectionString属性添上连接字符串,连接成功。如果在程序中填写则连接失
- 制作软件注册页面时出现的问题!
- DBgrid中有一个字段内容很多,怎样让这个字段的内容以多行显示?
- pascal初学者问题,急!!!!!
- 三层的系统, 由于不想在注册表里产生垃圾, 所以不使用com/dcom , 只好使用corba, 但是corba无法穿透防火墙, 有另外的什么办法吗? 比如 we
- 我现在需要像银行那样的打印存折的册子,不知道怎么打。
- QuickRep在哪里?
- 给Access数据库“减肥”
- 关于窗体最小化!请进!
- 马上要出国了,可是最近接到通知,要打N个预防针,怎么办啊我晕针,救命啊大家帮我出出注意好吗?
DLL的入口也很重要
aparam:TDllParams;
begin
aparam := TDllParams.Create;
aparam.PrjServerIp := '10.160.16.142';
aparam.PrjServerPort := 211;
DoDllFunction('E:\dlyx\Sources\temp\dll\Project2.dll','cccccc',aparam);
end;end.function DoDllFunction(aDllFile:String;aFunName:String;aParam:TDllParams):TDllResult;
var
DLLHandle : THandle;
aFunction : FDllFunction;
begin
DLLHandle := LoadLibrary( PChar(aDllFile) );//执行这句话出错了!!!!!!!
@aFunction := GetProcAddress(DllHandle,PChar(aFunName) );
if not Assigned(aFunction) then
raise Exception.Create('导入插件错误!');
result := aFunction(aParam);
end;
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,
Unit1 in 'Unit1.pas' {frmTemp},
UserUtil in '..\..\Pub\UserUtil.pas',
AuditMng in '..\..\Pub\AuditMng.pas',
AuditMngClient in '..\..\Pub\AuditMngClient.pas',
AuditObjs in '..\..\Pub\AuditObjs.pas',
ClientConfig in '..\..\Pub\ClientConfig.pas',
ClientSystem in '..\..\Pub\ClientSystem.pas',
DirectoryDialog in '..\..\Pub\DirectoryDialog.pas',
DynDll in '..\..\Pub\DynDll.pas',
EntityBaseObj in '..\..\Pub\EntityBaseObj.pas',
GlobalConst in '..\..\Pub\GlobalConst.pas',
ServerConfig in '..\..\Pub\ServerConfig.pas',
ServerSystem in '..\..\Pub\ServerSystem.pas',
SqlConfig in '..\..\Pub\SqlConfig.pas',
SysMng in '..\..\Pub\SysMng.pas',
SysMngClient in '..\..\Pub\SysMngClient.pas',
SysObjs in '..\..\Pub\SysObjs.pas',
TestMainliFrm in '..\..\Pub\TestMainliFrm.pas' {TestMainliForm},
AppConst in '..\..\Pub\AppConst.pas';
function cccccc(adllparam:tdllparams):tdllresult;stdcall;
var
frmTemp: TfrmTemp;
begin
frmTemp := TfrmTemp.Create(nil);
frmTemp.iniform(adllparam);
frmTemp.Visible := true;
end;
{$R *.res}
exports
cccccc;
begin
end.
估计是前次调用DLL没有释放。
是個類的實例, 在dll與主exe間,不能這樣傳遞 對象指針的, 經常會有問題的, 參考:
http://borland.mblogger.cn/aiirii/posts/12450.aspx
关键代码没贴出来
frmTemp.iniform(adllparam);干啥了?
function cccccc(Classaddr:Integer):tdllresult;stdcall;
begin
……
frmTemp.iniform(Tdllparams(Pointer(Classaddr)));
……
end;然后在调用的代码里把类的地址传进去
function DoDllFunction(aDllFile:String;aFunName:String;classaddr:Integer):TDllResult;……
DoDllFunction('E:\dlyx\Sources\temp\dll\Project2.dll','cccccc',Integer(Tdllparams));……
var
DLLHandle : THandle;
aFunction : FDllFunction;
begin
try
DLLHandle := LoadLibrary( PChar(aDllFile) );//执行这句话出错了!!!!!!!
@aFunction := GetProcAddress(DllHandle,PChar(aFunName) );
if not Assigned(aFunction) then
raise Exception.Create('导入插件错误!');
result := aFunction(aParam);
except
ShowMessage(IntToStr(GetLastError())); // see the error code..
end;
end;