I need to set two environmental variables (when my application runs) for included 3rd party libraries.
The problem is that 'that way' it is not working, however when I run console application, set these two variables and then run the application, everything is okay ...
how to configure these two vars correctly?
i use the procedure:
function SetEnvVarValue(const VarName,
VarValue: string): Integer;
begin
// Simply call API function
if SetEnvironmentVariable(PChar(VarName),
PChar(VarValue)) then
Result := 0
else
Result := GetLastError;
end;
It returns 0
Maybe the thing is, that i have the libraries being loaded on application startup. When my application stars I set then the variables and I do it too late ...?
Further information
I have included two units in dpr:
ImageMagick in 'C:\Program Files (x86)\Borland\Delphi7\Lib\Magick\magick\ImageMagick.pas', magick_wand in 'C:\Program Files (x86)\Borland\Delphi7\Lib\Magick\wand\magick_wand.pas';
And the Unit:
unit DoItFirst;
interface
uses
Windows, Sysutils;
var
s: string;
error: Integer;
function _putenv_s(const lpName, lpValue: PChar): BOOL; cdecl; external 'msvcrt.dll';
implementation
function GetEnvVarValue(const VarName: string): string;
var
BufSize: Integer; // buffer size required for value
begin
// Get required buffer size (inc. terminal #0)
BufSize := GetEnvironmentVariable(PChar(VarName), nil, 0);
if BufSize > 0 then
begin
// Read env var value into result string
SetLength(Result, BufSize - 1);
GetEnvironmentVariable(PChar(VarName),
PChar(Result), BufSize);
end
else
// No such environment variable
Result := '';
end;
initialization
_putenv_s(PChar('DYLD_LIBRARY_PATH'), PChar('g:\_projekty\ZBar Test\'));
_putenv_s(PChar('MAGICK_CODER_MODULE_PATH'), PChar('g:\_projekty\ZBar Test\modules\coders\'));
s := GetEnvVarValue('DYLD_LIBRARY_PATH');
s := GetEnvVarValue('MAGICK_CODER_MODULE_PATH');
end.
This unit is at the beginning of dpr file.