Solved

LoadLibaray Not Working

Posted on 2010-11-17
10
346 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:nchannon
Comment Utility
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
Comment Utility
What does 'GetLastError()' report?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:nchannon
Comment Utility
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
Comment Utility
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
Comment Utility
Last thing : if you work with MFC, you'd better use ::AfxLoadLibrary.
0
 

Author Comment

by:nchannon
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now