Sign in to follow this  

DLL Loading Problem

This topic is 3341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, everyone. I have a problem with loading a dll in my program using LoadLibrary( LibaryName ). I'm only having that problem with a particular dll and never had that problem before. All of my other dlls are loadable and usable without problems. No significant changes have been made since the last successful use of the dll in my exe. Here's the general format of my dll and all my other dlls: #include <windows.h> #include <stdio.h> #include <math.h> #include <ctime> #include <cstdlib> /* (global constants and some global variables here) (function and class declarations here) (global variables here) */ #ifdef __cplusplus extern "C" { #endif __declspec(dllexport) void __cdecl SomeFunction1( /* arguments */ ) { // bla bla bla } // the list continues... BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } #ifdef __cplusplus } #endif To exclude the possibility that something was wrong in my main program that caused the error, I've made a simple console program that just loads the dll using LoadLibrary(), and as expected it returned NULL. I've tried using GetLastError after the dll failed to load but it just returned a 0. One of the possible causes that I can think of is my recent installation of SP3 for WinXP on my PC. Any suggestions and/or solutions are greatly appreciated.

Share this post


Link to post
Share on other sites
Just to clarify, only your DLL fails to load (returns NULL from LoadLibrary())? First thing I'd try is getting rid of DllMain() and seeing if you can LoadLibrary() then.
You could also try running dumpbin on your DLL to see if it can be parsed by that (Although I'll be surprised if it can't), and also running depends on it to see if it's using any odd DLLs itself that for some reason can't be loaded by the EXE.
And that you're not trying to load a x64 DLL in an x86 EXE or suchlike.

Are you calling GetLastError() immediately after LoadLibrary fails? Before any other function calls? If not, then functions like MessageBox will reset the last error to 0 (No error).

Share this post


Link to post
Share on other sites
If the exported functions do not accept a variable number of arguments, consider changing their calling convention stipulation from __cdecl to __stdcall. That way there is less room for error in the code that eventually calls what become imported functions. That's an aside to your stated problem.

Given that you're only having troubles with one dll, it might be that the loader is unable to find the dll. See Dynamic-Link Library Search Order for insights. Along that line, double check that you've spelled the name of the dll correctly in your code and that the dll resides in the directory where your code expects it to reside.

A very useful free utility for dealing with dll loading problems is Dependency Walker. Check it out, it might help you resolve the problem.


Share this post


Link to post
Share on other sites

This topic is 3341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this