Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS and Delphi - Get the application folder inside ISAPI

Tags:

iis

delphi

isapi

When running an ISAPI application on IIS, if we call ParamStr(0) or Application.ExeName inside our ISAPI we will get the folder that IIS is installed (C:\windows...).

Is there any way of getting the folder path which contains my ISAPI instead of IIS's application folder?

like image 865
Rafael Colucci Avatar asked Oct 17 '11 12:10

Rafael Colucci


1 Answers

Your ISAPI application is a library (DLL), therefore you can use this approach to get its folder:

ExtractFilePath(GetModuleName(HInstance))

Use ExtractFileDir() instead of ExtractFilePath() if you don't need the last backslash.

Rationale: According to Delphi docs,

Several variables declared in the System unit are of special interest to those programming libraries. ... During a library's lifetime, HInstance contains its instance handle.

Using GetModuleName() you get that DLL's file name. ParamStr(0), on the other hand, contains the name of the main EXE where this DLL has been loaded to.

like image 192
haimg Avatar answered Oct 29 '22 12:10

haimg