Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Change BPL Windows\system path to another one?


This question is answered.


Permlink Replies: 11 - Last Post: Jul 19, 2016 9:50 AM Last Post By: Remy Lebeau (Te...
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Change BPL Windows\system path to another one?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 16, 2016 7:02 AM
Hello,

I created a more that one program that all of them must
link with run-time packages and i need them to share the
same Bpls when deployed on end users.

But i don't want to use "C:\Windows\system" path for that.
I want it to be on "D:\My Programs\Libs" and all my projects
should this path instead of windows\system to look for bpls

vcl.bpl
rtl.bpl
.etc.

Any help will be appreciated. Thanks in advance.

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Change BPL Windows\system path to another one?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 16, 2016 4:51 PM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

But i don't want to use "C:\Windows\system" path for that.

Nor should you. They don't belong there.

I want it to be on "D:\My Programs\Libs" and all my projects
should this path instead of windows\system to look for bpls
vcl.bpl
rtl.bpl
.etc.

BPLs are just DLLs with added support for the RTL/VCL/FMX frameworks. Assuming
you are not explicitly loading the BPLs with LoadPackage() and absolute paths,
then the BPLs will be located the same way any DLL is located. As such,
you can use the Win32 API SetDllDirectory() or AddDllDirectory() function
to add a custom path to the DLL search order, or add your custom path to
the user/system's %PATH% environment variable.

See MSDN for more details:

Dynamic-Link Library Search Order
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586.aspx

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: Change BPL Windows\system path to another one?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 16, 2016 11:58 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks for the reply, But where exactly should I use SetDllDirectory
or AddDllDirectory. Before the application initialize or at main
form constructor?

And another thing that might get in the way all these programs
will run by standard users on windows 7 not admins. So, do these
functions SetDllDirectory or AddDllDirectory will work with a standard user?

Also, what do you mean by?
add your custom path to 
the user/system's %PATH% environment variable.


You mean in IDE or on the deployment computer? And if it is changed
from within the IDE. How is that going to affect the app when it is deployed?

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Change BPL Windows\system path to another one? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 18, 2016 1:28 PM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

Thanks for the reply, But where exactly should I use SetDllDirectory
or AddDllDirectory. Before the application initialize or at main form
constructor?

They would only work if the BPLs are dynamically loaded at runtime, either
with explicit calls to the RTL's LoadPackage() function, or using the linker's
delay-load feature.

In the latter case, you could use a delay-load hook to call the functions
during the dliNoteStartProcessing or dliNotePreLoadLibrary stage (LoadPackage()
uses LoadLibrary() internally).

And another thing that might get in the way all these programs will
run by standard users on windows 7 not admins. So, do these functions
SetDllDirectory or AddDllDirectory will work with a standard user?

They should, yes.

Also, what do you mean by?

add your custom path to
the user/system's %PATH% environment variable.


You mean in IDE or on the deployment computer?

The deployment computer.

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: Change BPL Windows\system path to another one? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 18, 2016 2:29 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

They would only work if the BPLs are dynamically loaded at runtime, either
with explicit calls to the RTL's LoadPackage() function, or using the linker's
delay-load feature.

In the latter case, you could use a delay-load hook to call the functions
during the dliNoteStartProcessing or dliNotePreLoadLibrary stage (LoadPackage()
uses LoadLibrary() internally).

I am sorry but i don't understand that part? I am not talking about
custom made BPL files but i meant the ones found in the Redist folder
with IDE files Like (vcl230.bpl, rtl230.bpl. etc) So, I will not load them
manually because the application will load them for me.

For example should i use it this way:
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1);
//---------------------------------------------------------------------------
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
	try
	{
                UnicodeString ANewPath = "D:/My Systems/redist"
                SetDllDirectoryW(ANewPath.w_str());
 
		Application->Initialize();
		Application->MainFormOnTaskBar = true;
		Application->CreateForm(__classid(TForm1), &Form1);
		Application->Run();
	}
	catch (Exception &exception)
	{
		Application->ShowException(&exception);
	}
	catch (...)
	{
		try
		{
			throw Exception("");
		}
		catch (Exception &exception)
		{
			Application->ShowException(&exception);
		}
	}
	return 0;
}
//---------------------------------------------------------------------------


Or in function called in pragma startup would be better.

Also, what delay-load feature you are talking about? And
why would i need to delay load the vcl run-time packages?

Also, is there a way where i can trick the app to run it as if there
is no IDE installed? as if this is the deployment computer?
Because it is really hard to build an app then test it on another machine
every half-hour or something like that?

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Change BPL Windows\system path to another one? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 18, 2016 4:18 PM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

I am sorry but i don't understand that part? I am not talking about
custom made BPL files but i meant the ones found in the Redist folder
with IDE files Like (vcl230.bpl, rtl230.bpl. etc) So, I will not load
them manually because the application will load them for me.

Then you are most likely out of luck, since those BPLs will be loaded before
your app's WinMain() is entered.

Otherwise, just place the BPLs in the system's search path. The best place
is in the same folder as your app's executable.

Or in function called in pragma startup would be better.

Possibly. It depends on whether your custom startup function gets called
before or after the RTL is initialized. I don't know.

Also, what delay-load feature you are talking about?

It is an advanced option of the linker that allows you to static-link to
a DLL at compile-time, but not load it at runtime until the first time it
is actually used by the app's code.

And why would i need to delay load the vcl run-time packages?

When you static-link to a DLL (and a BPL is just a DLL), it is loaded by
the OS before any code in the application is run. In this scenario, your
app has no control over how the DLL is located. If the DLL cannot be loaded,
or any exports you static-link to are missing, your whole app fails to run
at all.

When you delay-load a DLL, you are still static-linking to its exports at
compile-time, but they are loaded dynamically at runtime only when your app
uses them for the first time. This gives the application code a chance to
run first, and decide whether or not to use them (great when calling newer
APIs that don'e exist on older OS versions). This also gives the app code
a chance to assign callback hooks in the delay loader, so the app can detect
delay-load errors (missing DLL, missing exports, etc), and possibly even
recover from them (load an alternative DLL, return alternative function pointers,
etc).

Also, is there a way where i can trick the app to run it as if there
is no IDE installed? as if this is the deployment computer?

No. You would need a real deployment system that does not have the IDE installed
in it.

Because it is really hard to build an app then test it on another
machine every half-hour or something like that?

If you don't have access to a physical machine to test on, use a virtual
machine instead.

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: Change BPL Windows\system path to another one? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 18, 2016 4:31 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:


Then you are most likely out of luck, since those BPLs will be loaded before
your app's WinMain() is entered.

Otherwise, just place the BPLs in the system's search path. The best place
is in the same folder as your app's executable.

Possibly. It depends on whether your custom startup function gets called
before or after the RTL is initialized. I don't know.

Then, How can I make sure that my start up function runs before WinMain
does or before initializing RTL?

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Change BPL Windows\system path to another one? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 18, 2016 4:42 PM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

Then, How can I make sure that my start up function
runs before WinMain does or before initializing RTL?

Any startup function you call with #pragma, or any global object you create
in static memory, will run before WinMain(). But it may not necessarily
run before the RTL's own startup code runs first. You could try playing
around with #pragma startup priorities, but I have a feeling that will not
be enough.

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: Change BPL Windows\system path to another one? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 19, 2016 1:07 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Any startup function you call with #pragma, or any global object you create
in static memory, will run before WinMain(). But it may not necessarily
run before the RTL's own startup code runs first. You could try playing
around with #pragma startup priorities, but I have a feeling that will not
be enough.

How about that other option to add a new search path to Path Environment variables
on deployment machine do I have to do it from my C++Builder Apps or can I do it in
installer like "InstallAware" or "InnoSetup" during setup process?

Do RAD Studio apps will search automatically for the new search path without any
modifications? I mean:

1- If the app didn't find the BPLs in Windows\system
2- Then it will look in my newly added custom path.

Right? Correct me if i am wrong?

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Change BPL Windows\system path to another one? [Edit]
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 19, 2016 9:50 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

How about that other option to add a new search path to Path
Environment variables on deployment machine do I have to do it
from my C++Builder Apps or can I do it in installer like "InstallAware"
or "InnoSetup" during setup process?

It would have to be done from an installer.

Do RAD Studio apps will search automatically for the new search path
without any modifications? I mean:

1- If the app didn't find the BPLs in Windows\system 2- Then it will
look in my newly added custom path.

Right? Correct me if i am wrong?

Read the documentation:

Dynamic-Link Library Search Order
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586.aspx

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Re: Change BPL Windows\system path to another one? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 19, 2016 1:30 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I found that i can run this script in InstallAware during installation:

Set Environment Variable %path% to D:\AUB Windows Apps\system\redist\win32

Will that do the trick for me and force RAD Apps to look for bpls in that directory?

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Change BPL Windows\system path to another one? [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 19, 2016 9:48 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote::

Will that do the trick for me and force RAD Apps to look
for bpls in that directory?

It will include your directory as one of many that the BPLs will be searched
in. But it will not be the first place the OS looks, it will be the last.
Read the documentation:

Dynamic-Link Library Search Order
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586.aspx

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02