Solved

LoadLibrary

Posted on 1997-04-22
2
2,296 Views
Last Modified: 2008-03-06
I am having some difficulty with the LoadLibrary function in the Windows
API.  When I try and load a dll (which I made) GetLastError returns 126 but the function DOES NOT return NULL.
The documentation identifies this error as RROR_MOD_NOT_FOUND.  I was
certain I was specifying the correct name.  So I considered maybe my DLL
was improper in some way.  So I tried to load another dll (one that I
randomly selected from the windows directory) and GetLastError return 31
OR_GEN_FAILURE.  If I attempt to link the import library for my DLL to
the exectuble then everything works great.  So I am pretty certain my
DLL works fine.  For my purposes I need to dynamically load my DLL
however and I havn't been able to get LoadLibrary to work on my DLL or
any other.  Does anybody have any ideas?

0
Comment
Question by:tlsoftware
2 Comments
 
LVL 3

Expert Comment

by:rmichels
ID: 1162910
Can you show the code you are using.  How are you specifying the path name of the module (the parameter to LoadLibrary)?  Is the DLL file in the current search path for DLL modules?
0
 
LVL 1

Accepted Solution

by:
shappir earned 50 total points
ID: 1162911
There are several issues to consider when using LoadLibrary:1. The module (DLL) file must reside in a directory where it will be found. Check the documentation for LoadLibrary for information on where Windows looks for the file.2. Beware of name (file name) conflicts with other modules in the system.3. Don’t try to load a 16-bit DLL from a 32-bit program or the other way around.4. If possible, create the DLL using the same language/compiler as the main application. Otherwise you may have naming problems and incompatible library calls.5. If you create your DLL in C/C++ use the same RTL as the main application (single threaded or multi-threaded or mt DLL).6. If the DLL uses __declspec(thread) LoadLibrary will fail. You must use the TLS API instead.Hope this helps, if not try to create the simpleset possible application that just does LoadLibrary and see if it works. If not, post it here.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now