问题描述
在卸载动态包并调用UnloadPackage
功能?
var
MyPackageHandle : THandle;
begin
MyPackageHandle := LoadPackage('.\MyPackage.bpl');
if(MyPackageHandle <> 0) then
UnloadPackage(MyPackageHandle);
end;
在这种情况下,我需要在 MyPackage.bpl 中执行一些代码,
In this case, I need to execute some code inside MyPackage.bpl when it's unloaded
推荐答案
一般规则是,当将程序包卸载到单元的finalization
部分时,应放置需要调用的代码.我从您的其他软件包中知道您正在尝试卸载dll.但是要注意的是,永远不要从initialization
或finalization
加载/卸载dll.
The general rule is that you should put code that needs to be called when your package is unloaded into the finalization
part of your unit. I know from your other package that you're trying to unload a dll. But the catch is that should never load/unload a dll from initialization
or finalization
.
因此,您需要做的是在程序包中有一个函数,您可以从主应用程序中调用该函数来执行清理工作.
So what you need to do is have a function in your package that you will call from your main application, that performs the clean-up.
type
TCleanup = procedure;
var
MyPackageHandle : THandle;
CleanupProc: TCleanup;
begin
MyPackageHandle := LoadPackage('.\MyPackage.bpl');
if(MyPackageHandle <> 0) then
begin
@CleanupProc := GetProcAddress(MyPackageHandle, 'Cleanup' );
if @CleanupProc <> nil then
CleanupProc;
UnloadPackage(MyPackageHandle);
end;
end;
这篇关于如何从目标BPL中检测UnloadPackage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!