Thread View: borland.public.cppbuilder.nativeapi
10 messages
10 total messages
Started by nicolasr
Tue, 01 Apr 2003 14:57
Does a DLL know its own path?
Author: nicolasr
Date: Tue, 01 Apr 2003 14:57
Date: Tue, 01 Apr 2003 14:57
7 lines
988 bytes
988 bytes
Hi, I'm writing a pure WinAPI DLL. Is there a way from within the DLL to get at the path of the DLL ? thanks, Nick
Re: Does a DLL know its own path?
Author: Nick B. Cassos
Date: Tue, 01 Apr 2003 15:47
Date: Tue, 01 Apr 2003 15:47
22 lines
1531 bytes
1531 bytes
On Tue, 1 Apr 2003 16:57:55 +0200, "nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote: >Hi, > >I'm writing a pure WinAPI DLL. Is there a way from within the DLL to get at >the path of the DLL ? > >thanks, >Nick > I think, you should start with GetModuleFileName() to obtain the path of your DLL's process. Armed with this info, you can follow Window's logic to look first in the process's directory, then the current one, system, windows, and anything in the PATH environment string. If there are 2 or more instances of your DLL in several directories then I give up. -- Nick B. Cassos
Re: Does a DLL know its own path?
Author: Early Ehlinger
Date: Tue, 01 Apr 2003 16:12
Date: Tue, 01 Apr 2003 16:12
36 lines
2356 bytes
2356 bytes
"Nick B. Cassos" <nbc@no_spam.ath.forthnet.gr> wrote:
> I think, you should start with GetModuleFileName() to obtain the path
> of your DLL's process. Armed with this info, you can follow Window's
> logic to look first in the process's directory, then the current one,
> system, windows, and anything in the PATH environment string. If there
> are 2 or more instances of your DLL in several directories then I give
> up.
GetModuleFileName returns the fully-qualified filename, so there's no need
to search any paths. Simply pass this API the HINSTANCE that the OS passes
to you in DllMain:
BOOL WINAPI DllMain
( HINSTANCE hinstDLL
, DWORD dwReason
, LPVOID lpvReserved )
{
switch( dwReason )
{
case DLL_PROCESS_ATTACH:
{
std::vector< char > path( MAX_PATH + 1 );
Win32Check( GetModuleFileName
( reinterpret_cast< HMODULE >( hinstDLL )
, &*path.begin()
, path.size( ) ) );
/* Note: you should really use a loop to handle
paths longer than MAX_PATH, but that's an
exercise for the reader :-) */
}
}
}
--
-- Early Ehlinger CEO, ResPower Inc - Toll-Free : 866-737-7697
-- www.respower.com -- 500+ GHz Supercomputer Starting At USD$0.50/GHz*Hour
Re: Does a DLL know its own path?
Author: Remy Lebeau (TeamB)
Date: Tue, 01 Apr 2003 18:46
Date: Tue, 01 Apr 2003 18:46
13 lines
1366 bytes
1366 bytes
"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote in message news:3e89a8e5$1@newsgroups.borland.com... > I'm writing a pure WinAPI DLL. Is there a way from > within the DLL to get at the path of the DLL ? Look at the GetModuleFileName() and related functions. You will have to retreive the DLL's own module handle, don't use NULL as that will return the calling application's filename instead. Gambit
Re: Does a DLL know its own path?
Author: nicolasr
Date: Tue, 01 Apr 2003 18:58
Date: Tue, 01 Apr 2003 18:58
3 lines
1040 bytes
1040 bytes
thanks guys for the help. It works well. Nick
Re: Does a DLL know its own path?
Author: nicolasr
Date: Tue, 01 Apr 2003 19:00
Date: Tue, 01 Apr 2003 19:00
6 lines
1086 bytes
1086 bytes
Hi, I have tried GetModuleFileName() with the HINSTANCE that is passed to DllEntryPoint() and that seems to work well. thanks, Nick
Re: Does a DLL know its own path?
Author: Nick B. Cassos
Date: Wed, 02 Apr 2003 07:27
Date: Wed, 02 Apr 2003 07:27
26 lines
1976 bytes
1976 bytes
On Tue, 1 Apr 2003 10:12:33 -0600, "Early Ehlinger" <early@respower.com> wrote: >"Nick B. Cassos" <nbc@no_spam.ath.forthnet.gr> wrote: >> I think, you should start with GetModuleFileName() to obtain the path >> of your DLL's process. Armed with this info, you can follow Window's >> logic to look first in the process's directory, then the current one, >> system, windows, and anything in the PATH environment string. If there >> are 2 or more instances of your DLL in several directories then I give >> up. > >GetModuleFileName returns the fully-qualified filename, so there's no need >to search any paths. Simply pass this API the HINSTANCE that the OS passes >to you in DllMain: > The original poster asked for the path of his own DLL and not of the process where the DLL is attached. According to SDK: "If a DLL is loaded in two processes, its file name in one process may differ in case from its file name in the other process." -- Nick B. Cassos
Re: Does a DLL know its own path?
Author: Nick B. Cassos
Date: Wed, 02 Apr 2003 07:45
Date: Wed, 02 Apr 2003 07:45
14 lines
1404 bytes
1404 bytes
On Tue, 1 Apr 2003 10:12:33 -0600, "Early Ehlinger" <early@respower.com> wrote: > >GetModuleFileName returns the fully-qualified filename, so there's no need >to search any paths. Simply pass this API the HINSTANCE that the OS passes >to you in DllMain: > Please, ignore my previous post. I was misunderstood. -- Nick B. Cassos
Re: Does a DLL know its own path?
Author: Ed Mulroy [TeamB]
Date: Wed, 02 Apr 2003 13:49
Date: Wed, 02 Apr 2003 13:49
23 lines
2051 bytes
2051 bytes
It could be loaded as a long file name by one process and as a short file name by another. Additionally it might have been loaded from a relative path in one and an absolute path by another and using a path set up with the subst command by yet another. I am not sure that all of these will alter the result of calling GetFullPathName but the SDK note seems to imply that it will. I think a way around that is to call GetFullPathName on the returned value from GetModuleFileName. That should give the same representation of path and file name independent of short vs long names and real vs subst paths. . Ed > Nick B. Cassos wrote in message > news:fv3l8v4q3fguthh808a3htirmii4lj4c0o@4ax.com... > > > The original poster asked for the path of his own DLL > and not of the process where the DLL is attached. > > According to SDK: "If a DLL is loaded in two processes, > its file name in one process may differ in case from its > file name in the other process."
Re: Does a DLL know its own path?
Author: Early Ehlinger
Date: Wed, 02 Apr 2003 17:09
Date: Wed, 02 Apr 2003 17:09
11 lines
1487 bytes
1487 bytes
"Nick B. Cassos" <nbc@no_spam.ath.forthnet.gr> wrote: > The original poster asked for the path of his own DLL and not of the > process where the DLL is attached. That's exactly what the HINSTANCE passed to DllMain/DllEntryPoint is - the handle to the DLL as opposed to the handle to the process. -- -- Early Ehlinger CEO, ResPower Inc - Toll-Free : 866-737-7697 -- www.respower.com -- 500+ GHz Supercomputer Starting At USD$0.50/GHz*Hour
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads