[Lazarus] Setting environment variables for libraries

Aradeonas aradeonas at operamail.com
Fri Dec 11 00:32:32 CET 2015


Hi,

I have many libraries (dll,so) and they come with wrappers with constant
library path and file name. I want to move these libraries to a specific
folder and load from there so one way I know is to change them and load
them dynamicly but I cant do it every time new library version came out
with new changes.

So I hope there be a some kind of virtual environment variables so when
I call x.dll, it search also there and conenct to it like when you put
dll in system32 in windows and your program will find it. I dont want to
change system environment variables because these libraries will use
only in my program.

I tried something like this:

> program project1;
>
> {$mode objfpc}{$H+}
>
> uses {$IFDEF UNIX} {$IFDEF UseCThreads}  cthreads, {$ENDIF} {$ENDIF}
> Interfaces, // this includes the LCL widgetset  Forms,  Unit1 { you
> can add units after this },  SysUtils,  Windows;
>
> {$R *.res}
>
> var  s: string; var  oldPath: string; // Original PATH value
> buildPath: string; // Intermediate path for setting new environment
> variable  newPath: string; // Retrieve the PATH again and compare
> against oldPath begin  s := ExtractFilePath(ParamStr(0)) +
> 'libra\32\';  //SetDllDirectory(PChar(s));
>
> oldPath := SysUtils.GetEnvironmentVariable('PATH');  buildPath :=
> oldPath + ';' + s;  if SetEnvironmentVariable('PATH',
> PChar(buildPath)) then  begin    writeln('PATH updated!');    newPath
> := SysUtils.GetEnvironmentVariable('PATH');  end;
>
> writeln;  writeln('Showing old path:');  writeln(oldPath);  writeln;
> writeln('Showing new path:');  writeln(newPath);  //readln;
>
>
> RequireDerivedFormResource := True;  Application.Initialize;
> Application.CreateForm(TForm1, Form1);  Application.Run; end.


>
> unit Unit1;
>
> {$mode objfpc}{$H+}
>
> interface
>
> uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics,
> Dialogs,LCLType,BASS,windows;
>
> { TForm1 }
>
> type  TForm1 = class(TForm)    procedure FormCreate(Sender:
> TObject);  private    { private declarations }  public    { public
> declarations }  end;
>
> var  Form1: TForm1;
>
> implementation
>
> {$R *.lfm}
>
> { TForm1 }
>
> procedure TForm1.FormCreate(Sender: TObject); begin
>
> if (HIWORD(BASS_GetVersion) <> BASSVERSION) then        begin
> ShowMessage('BASS_GetVersion');                Halt;        end;
>
> // Initialize audio - default device, 44100hz, stereo, 16 bits
> if not BASS_Init(-1, 44100, 0, Handle, nil) then
> ShowMessage('BASS_Init'); end; end.


As you can see project file uses Unit1 and it uses BASS and it wants to
call dll before our path changes! :| How can I solve this?

Regards, Ara

-- 
http://www.fastmail.com - Access your email from home and the web

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20151210/f6801096/attachment-0002.html>


More information about the Lazarus mailing list