LoadLibaray Not Working

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
nchannonAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Xper4netConnect With a Mentor Commented:
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
 
Xper4netCommented:
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
 
jkrCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
denissieCommented:
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
 
nchannonAuthor Commented:
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
 
jkrCommented:
What does 'GetLastError()' report?
0
 
nchannonAuthor Commented:
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
 
Xper4netCommented:
Classical issue...don't worry, you're not the first, and surely not the last to face it ;-)
0
 
Xper4netCommented:
Last thing : if you work with MFC, you'd better use ::AfxLoadLibrary.
0
 
nchannonAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.