Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / December 2004

Tip: Looking for answers? Try searching our database.

DLL search path question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Piotr Szukalski - 29 Dec 2004 15:01 GMT
Hi!

I have a simple (?) DLL-loading question:
Here's my trouble in details:
- there are two DLLs: a.dll and b.dll
- a.dll and b.dll are in the same directory
- a.dll uses b.dll in a #pragma comment (lib 'b.lib') way
- a.dll is being loaded by some external APP stored in a different folder
- b.dll can't be found :(

The thing I want is a.dll searching for b.dll in a.dll folder, not APP
folder. I know I can set %PATH% or
'HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths' reg. key, but
I'd prefer to avoid both... copying DLLs into system32 is not an option
as well.
I use VS .NET 2003, DLLs are pure C++

Thanks in advance,
 Piotrek
Mikhail Arkhipov (Microsoft) - 29 Dec 2004 23:35 GMT
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/loadlibrary.asp

The search order is as follows

  1. The directory from which the application loaded.
  2. The system directory. Use the GetSystemDirectory function to get the
path of this directory.
  3. The 16-bit system directory. There is no function that obtains the
path of this directory, but it is searched.

         Windows Me/98/95:  This directory does not exist.

  4. The Windows directory. Use the GetWindowsDirectory function to get the
path of this directory.
  5. The current directory.
  6. The directories that are listed in the PATH environment variable.

As you can see, load location of a random dll in a chain of dlls is not
used, only application directory, path and Windows directories apply. Hence
if you want a.dll to find b.dll without placing them on a path or in
system32, you'll have to manually load them (i.e. Construct loading path
according to your custom rules and call LoadLibrary with the full path.

Alternatively, if you use COM objects, you can make object in b.dll to be a
COM object, register it in registry and have a.dll to instantiate it using
CoCreateInstance. In this case dll search rules do not apply since correct
path is listed in the registry.

Mikhail Arkhipov (Microsoft)
-- This post is provided 'AS IS' with no warranties and confers no rights

On 12/29/04 7:05, in article
pan.2004.12.29.15.05.22.808000@SPAM-AWAYpoczta.onet.pl, "Piotr Szukalski"
<amigos_@SPAM-AWAYpoczta.onet.pl> wrote:

> Hi!
>
[quoted text clipped - 15 lines]
> Thanks in advance,
>   Piotrek

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.