We help IT Professionals succeed at work.

File location of loaded dll

WiseGuy
WiseGuy asked
on
Medium Priority
182 Views
Last Modified: 2010-04-06
Dear Experts,

We have build dll's. They use ini-files. The ini-file is situated next to the dll.
Within the code of the dll we need to determine the filepath to the dll file, so we know where the ini file is at.

It will have to work for win95, win98, win2000, and winnt4

Ramon 'WiseGuy' Huijbens
Comment
Watch Question

Commented:
Listening..
I have the same problem with ISAPI dll's
Motaz

Author

Commented:
Well I' am still trying to solve it myself.
When I succeed we could flip sides. You'll ask the question, I give the answer, and I get the points (yes, yes).
Commented:
Piece of cake:

var DllMod:integer;
    ModName:array [0..255] of char;
    FPath:string;
begin
   DllMod:=LoadLibrary('olepro32.dll'); /// for example
   GetModulefileName(dllmod,modname,255);
   FPath:=ExtractfilePath(modname);
   ShowMessage(modname);//full filename w/path
   ShowMessage(Fpath); ///Just the Path of filename
   FreeLibrary(dllmod);
end;



Good luck!!

Commented:
Sure WiseGuy.

DrDelphi, how that can be inside the Library?

Commented:
Inside of the dll it's even easier:

function GetCurrentModuleFileName : string;
var arrCh : array [0..MAX_PATH] of char;
begin
  GetModuleFileName(HInstance, arrCh, MAX_PATH);
  result := arrCh;
end;

Regards, Madshi.

Commented:
There should no difference, as long as the DLL is on the Path. Remember, each instance of the DLL runs in ots own process space, so you call load X.DLL from X.DLL. Of course, if you are going to do that, you might as well include a function that returns the path to the file.

For Example:

Function ShowPath:Pchar;
var MyName:array[0..255] of char;
begin
  GetModuleFilename(Hinstance,myname,255);
  Result:=MyName;
end;

Exports ShowPath;


Good luck!!
 

Commented:
Curses! I got back behind Madshi!<g>

Commented:
One minute faster...    =:-D

Commented:
It seems that I'll not lose any points:) isn't right WiseGuy:)

Author

Commented:
In the mean time I have found the same solution.

I will award the points though, but first I want Dr. Delphi to assure me that it works on all windows platforms.

Author

Commented:
In the mean time I have found the same solution.

I will award the points though, but first I want Dr. Delphi to assure me that it works on all windows platforms.

Commented:
It does. Oooops, I'm sorry, I'm not Dr. Delphi. I hope I may assure that, too?   :-)

Commented:
WiseGuy, Assure what Madshi said, he always acurate in his answers and comments
Motaz

Commented:
Sorry about that ,Wise.... I had to go take care of some bothersome business. Yes, it will work on all 32 bit versions of Windows.

cheers!

-DrD.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.