Solved

LoadLibaray Not Working

Posted on 2010-11-17
10
362 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

774 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