Article View: borland.public.cppbuilder.nativeapi
Article #17265Re: Does a DLL know its own path?
From: 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
Technical Details
Message-ID:
<3e89ba73@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3e89a8e5$1@newsgroups.borland.com> <ikcj8vkkoh627qccc57je6qv2d1uruhav1@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,9b751bad45db0bc8 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-01 08:18:22 PST From: "Early Ehlinger" <early@respower.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3e89a8e5$1@newsgroups.borland.com> <ikcj8vkkoh627qccc57je6qv2d1uruhav1@4ax.com> Subject: Re: Does a DLL know its own path? Date: Tue, 1 Apr 2003 10:12:33 -0600 Lines: 39 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 206.166.224.226 Message-ID: <3e89ba73@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1049213555 206.166.224.226 (1 Apr 2003 08:12:35 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail