I wrote a BPL project and added output .bpi file to another EXE project. The EXE project compiles and links well. The EXE runs well if I put .bpl file in the same folder as .exe file. However, the EXE fails to run if I put .bpl file in other folders than .exe file, and it shows "The program can't start because XXX.bpl is missing...".
I also wrote a DLL version and put .dll file in other folders than .exe file. I added the .dll to the EXE project's "C++ Linker"->"Advanced"->"Delay load DLLs" list, and added SetDllDirectory()
function call to my custom search path. The EXE runs well. It seems that .bpl can not work the same as .dll if delay-loaded with custom search path via SetDllDirectory()
, am I right?
Test BPL code is like following:
"TestPackage.h"
class PACKAGE TestPackage
{
TestPackage( void );
int GetInt( void );
};
"TestPackage.cpp"
#include "TestPackage.h"
#pragma package(smart_init)
TestPackage::TestPackage( void ){}
int TestPackage::GetInt( void ){ return 1000; }
And the test form application code is like following:
"TestApp.cpp"
#include "TestPackage.h"
void __fastcall TForm1::Button1Click( TObject* Sender )
{
TestPackage* package = new TestPackage;
int ret = package->GetInt();
Application->MessageBoxA( IntToStr(ret).c_str(), L"test", 0 );
}
I disabled both "Build with runtime packages" and "Dynamic RTL" in application options. I put TestPackage.bpl in the folder as EXE and the EXE worked well. I could upgraded BPL separately from EXE, say to let TestPackage::GetInt()
return other numbers. So the net result seems I can deploy my custom BPL with EXE, and other BPLs, like RTL and VCL, are still statically linked in EXE. The only limitation is that my custom BPL must be in the same folder as EXE, is there any way to overcome this?