Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

LoadLibaray Not Working

Posted on 2010-11-17
10
Medium Priority
?
383 Views
Last Modified: 2012-05-10
Hi can someone tell me is there a different approch to using loadlibaray from within a DLL than from within an exe.

For exampe when I load a dll from a exe the lib loads fine but if i try and load it from within another dll the dll is not loaded
0
Comment
Question by:nchannon
[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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:Xper4net
ID: 34155587
In most cases, LoadLibrary failed when a dependency (another DLL for example) is missing and/or not reachable by the system (neither in current directory, or by using PATH environment variable).

> Where are your DLL / your exe?
> What is your project type? MFC? Other?


0
 
LVL 86

Expert Comment

by:jkr
ID: 34155598
Can you be a bit more specific? I.e. calling 'LoadLibrary()' from within 'DllMain()' is not a good idea, whereas using that anywhere else should be fine...
0
 
LVL 4

Expert Comment

by:denissie
ID: 34156369
You can check if there's a dependency issue for a specific DLL or EXE using the freeware Dependency Walker

If there's no dependency issue, please elaborate as the usage of LoadLibrary from in an EXE or DLL is similar...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:nchannon
ID: 34158266
Hi im using MFC and I load the DLL from an app like this HMODULE hLib = LoadLibrary(_T("mydll.dll"))
when I call LoadLibrary mydll.dll loads fine but if I call LoadLibaray(_T("mydll.dll") )from within another dll eg:
seconddll.dll which then trys and load LoadLibrary(_T("mydll.dlll")) it dosn't load and hLib returns null.
My dll,s are all in the same directory
0
 
LVL 86

Expert Comment

by:jkr
ID: 34158325
What does 'GetLastError()' report?
0
 

Author Comment

by:nchannon
ID: 34158391
Ok found the problem DLL's were in the wrong directory for debugging they should of been the the main apps directory that was calling the first dll which inturn called the second dll I had them only in the root directory of the first dll so they werent avalible when the main app was running in debug mode
0
 
LVL 5

Expert Comment

by:Xper4net
ID: 34162873
Classical issue...don't worry, you're not the first, and surely not the last to face it ;-)
0
 
LVL 5

Expert Comment

by:Xper4net
ID: 34162883
Last thing : if you work with MFC, you'd better use ::AfxLoadLibrary.
0
 

Author Comment

by:nchannon
ID: 34163154
Yes feel a little silly on that one but hay im not the first and not the last :)
I tried AfxLoadLibrary can you tell me what the difference is between AFXLoadLibrary and LoadLibrary. What would be the benifits between the two
0
 
LVL 5

Accepted Solution

by:
Xper4net earned 2000 total points
ID: 34163994
AfxLoadLibrary is thread safe, and moreover, it performs special handling when your DLL is an "extension DLL" (DLL which uses DLL version of MFC).
Even if it is not your case, it should be one day, so it's better to use it from now.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

688 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