Solved

Calling a DLL from a DLL / LoadLibraryEx

Posted on 1999-01-05
5
675 Views
Last Modified: 2013-12-03
Consider application \a\foo.exe, which loads \b\first.dll via LoadLibraryEx( "\\b\\first", NULL, LOAD_WITH_ALTERED_SEARCH_PATH ).  Now, first.dll tries to access \b\second.dll via LoadLibraryEx( "second", NULL, 0 ) or LoadLibraryEx( "second", NULL, LOAD_WITH_ALTERED_SEARCH_PATH )...
both fail.  Just what does the ALTERED_SEARCH_PATH flag apply to?  MS documentation says it applies to "any associated executable modules that the specified module causes to be loaded."  Yes LoadLibrary can't find second.dll -- is there a way around this?  Hardcoding the path to second.dll inside first.dll is not an option.
0
Comment
Question by:wannamak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:wannamak
ID: 1418116
Edited text of question
0
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 1418117
As the docs state:
Note that the standard file search strategy and the alternate search strategy differ in just one way: the standard strategy starts its search in the calling application’s directory, and the alternate strategy starts its search in the directory of the executable module that LoadLibraryEx is loading.

As far as i can see (without hardcoding the path to the DLLs, which is indeed never a good idea), the only options you have are
- to place (both) '\a' and '\b' in your path environment
- install both DLLs in a 'well known' directory (such as the system or the windows directory
- install both DLLs in the application's directory
0
 

Author Comment

by:wannamak
ID: 1418118
The documentation is filled with phrases such as "the function uses the alternate file search strategy to find associated executable modules that the specified module causes to be loaded."  In my mind, my example is one where the "specified module" (first.dll) causes another (second.dll) to be loaded, yet the alternate search strategy fails.  I guess my question boils down to what the alternate search strategy applies to?

It does not apply to the "specified module" being loaded, as
LoadModuleEx( "\\b\\first.dll", NULL, 0 -or- LOAD..PATH ) works fine.

And it does not apply to other modules that the "specified module" loads, as
my original example fails.

For what, I wonder, does LoadLibraryEx search with the alternate strategy?

0
 
LVL 86

Expert Comment

by:jkr
ID: 1418119
As you specified a path in the call, it searches _associated_ modules in the 'alternate' path, e.g. if the DLL you're attempting to load has references to other modules, e.g. to '\\b\\third.dll'.
So, if e.g. '\anypath\anyexe.exe' loads '\b\first.dll' which attmpts to load '\b\second.dll' (explicitly!), the reference to the 'alternate' search path used before is superseded by the new context... If you used an import lib to bind 'second.dll' to 'first.dll', it should work as the docs state.
(And: I absolutely agree about the phrases)
0
 

Author Comment

by:wannamak
ID: 1418120
So the LOAD..PATH flag only applies to other dlls that have been _implicitly_ linked, not _explicitly_ (by LoadLibraryEx)!  For some reason, the fact that it was a parameter to LoadLibraryEx threw me off.  Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.Net Loading Word 11 109
How can i Install a new Data Source on Visual Studio 2 122
Need a complete list of ASP.NET page load events 3 73
Where did System.Data.Objects go? 2 72
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question