Discussion:
Open INI File in Same Directory as DLL
(too old to reply)
Rich Morey
2007-11-17 21:23:54 UTC
Permalink
Hi --

I would like to store some configuration in an INI file for my web app. I am
running a ISAPI DLL built with Delphi 7 running on IIS 6.0 on Windows 2003.
When I attempt to use the following code:

INIFILE := TStringList.Create;
INIFILE.LoadFromFile('CONFIG.INI')

The file is not found. I did a GetCurrentDir call and the "current"
directory was listed as the \windows\system directory! Have I configured
something incorrectly on my IIS server or is this a change in Windows? I am
planning to use the same DLL for a few projects so I want to have different
configuration info in the INI file.

Any help would be greatly appreciated.

Thanks,

Rich
Rabatscher Michael
2007-11-18 09:40:34 UTC
Permalink
Post by Rich Morey
Hi --
I would like to store some configuration in an INI file for my web app. I am
running a ISAPI DLL built with Delphi 7 running on IIS 6.0 on Windows 2003.
INIFILE := TStringList.Create;
INIFILE.LoadFromFile('CONFIG.INI')
The file is not found. I did a GetCurrentDir call and the "current"
directory was listed as the \windows\system directory! Have I configured
something incorrectly on my IIS server or is this a change in Windows?
No you haven't. As far as I know at startup the current diretory is set
to the path of the exe file -> in your case the IIS server. Your dll is
just loaded into the memory.

So I think best would be you fetch some preconfigured path from the
registry.

kind regards
Mike
Dennis Passmore
2007-11-18 12:24:11 UTC
Permalink
Post by Rich Morey
INIFILE.LoadFromFile('CONFIG.INI')
you will have to fully qualify the path to the INI file in order
to use it in several places as each place it might be used
might be in a different location.
Nicholas Brooks
2007-11-19 00:06:06 UTC
Permalink
Rich,

This is what we do:

uses
Windows;

function GetModuleAbsolutePath : String;
begin
SetLength(Result, MAX_PATH + 1); // Add 1 for the null character
GetModuleFileName(hInstance, PChar(Result), MAX_PATH + 1);
SetLength(Result, Length(PChar(Result)));
end;

So you'd then just do something like:

INIFILE.LoadFromFile(IncludeTrailingPathDelimiter(ExtractFileDir(GetModuleAbsolutePath)) + 'CONFIG.INI')


If you are going to put the config file in the same place as the DLL, make sure the Virtual Directory is secured enough so that nobody is able to actually get at the CONFIG.INI file. I.e. make sure the "Read" checkbox is unchecked under the Virtual Directory settings. Of course, if you have other resources underneath the virtual directory you don't want to do that.

The other option we have taken is to store the path in the Registry.


Cheers
Nicholas
Post by Rich Morey
Hi --
I would like to store some configuration in an INI file for my web app. I am
running a ISAPI DLL built with Delphi 7 running on IIS 6.0 on Windows 2003.
INIFILE := TStringList.Create;
INIFILE.LoadFromFile('CONFIG.INI')
The file is not found. I did a GetCurrentDir call and the "current"
directory was listed as the \windows\system directory! Have I configured
something incorrectly on my IIS server or is this a change in Windows? I am
planning to use the same DLL for a few projects so I want to have different
configuration info in the INI file.
Any help would be greatly appreciated.
Thanks,
Rich
Rich Morey
2007-11-19 15:12:04 UTC
Permalink
Great! I'll give this a try.

Thanks

Rich
Post by Nicholas Brooks
Rich,
uses
Windows;
function GetModuleAbsolutePath : String;
begin
SetLength(Result, MAX_PATH + 1); // Add 1 for the null character
GetModuleFileName(hInstance, PChar(Result), MAX_PATH + 1);
SetLength(Result, Length(PChar(Result)));
end;
INIFILE.LoadFromFile(IncludeTrailingPathDelimiter(ExtractFileDir(GetModuleAbsolutePath))
+ 'CONFIG.INI')
If you are going to put the config file in the same place as the DLL, make
sure the Virtual Directory is secured enough so that nobody is able to
actually get at the CONFIG.INI file. I.e. make sure the "Read" checkbox
is unchecked under the Virtual Directory settings. Of course, if you have
other resources underneath the virtual directory you don't want to do
that.
The other option we have taken is to store the path in the Registry.
Cheers
Nicholas
Post by Rich Morey
Hi --
I would like to store some configuration in an INI file for my web app. I
am running a ISAPI DLL built with Delphi 7 running on IIS 6.0 on Windows
INIFILE := TStringList.Create;
INIFILE.LoadFromFile('CONFIG.INI')
The file is not found. I did a GetCurrentDir call and the "current"
directory was listed as the \windows\system directory! Have I configured
something incorrectly on my IIS server or is this a change in Windows? I
am planning to use the same DLL for a few projects so I want to have
different configuration info in the INI file.
Any help would be greatly appreciated.
Thanks,
Rich
Rich Morey
2007-11-19 19:49:59 UTC
Permalink
Hi --

That worked great! Thank you so much. This will save me so much time down
the road!

Rich
Post by Nicholas Brooks
Rich,
uses
Windows;
function GetModuleAbsolutePath : String;
begin
SetLength(Result, MAX_PATH + 1); // Add 1 for the null character
GetModuleFileName(hInstance, PChar(Result), MAX_PATH + 1);
SetLength(Result, Length(PChar(Result)));
end;
INIFILE.LoadFromFile(IncludeTrailingPathDelimiter(ExtractFileDir(GetModuleAbsolutePath))
+ 'CONFIG.INI')
If you are going to put the config file in the same place as the DLL, make
sure the Virtual Directory is secured enough so that nobody is able to
actually get at the CONFIG.INI file. I.e. make sure the "Read" checkbox
is unchecked under the Virtual Directory settings. Of course, if you have
other resources underneath the virtual directory you don't want to do
that.
The other option we have taken is to store the path in the Registry.
Cheers
Nicholas
Post by Rich Morey
Hi --
I would like to store some configuration in an INI file for my web app. I
am running a ISAPI DLL built with Delphi 7 running on IIS 6.0 on Windows
INIFILE := TStringList.Create;
INIFILE.LoadFromFile('CONFIG.INI')
The file is not found. I did a GetCurrentDir call and the "current"
directory was listed as the \windows\system directory! Have I configured
something incorrectly on my IIS server or is this a change in Windows? I
am planning to use the same DLL for a few projects so I want to have
different configuration info in the INI file.
Any help would be greatly appreciated.
Thanks,
Rich
Continue reading on narkive:
Loading...