Search code examples
delphiiisisapi

IIS and Delphi - Get the application folder inside 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?


Solution

  • 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.