Solved

LoadLibrary

Posted on 1997-04-22
4
2,598 Views
Last Modified: 2008-02-26
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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Accepted Solution

by:
snemanov earned 50 total points
ID: 1162912
Hello,The GetLastError function returns the last occured error/warningand not a result of last called Win32 function.Not all functions call SetLastError(0) when they succeed,
so nothing indicates error in the LoadLibrary.Have You additional symptoms of error?Best regards, Sergey
0
 

Author Comment

by:tlsoftware
ID: 1162913
I considered that possibility so I called SetLastError(0) just before calling the LoadLibrary function.  It still returned error  126.  And a later call to GetProcAddress fails.  Any ideas?
0
 

Expert Comment

by:snemanov
ID: 1162914
Some ideas, tips and assumptions:1) There are many calls of Win32 functions into LoadLibrary() so the previous assumption still actual.2) I guess You have used wrong NAME MANGLING of the function name in the GetProcAddress.If you wish I'll not guess, just print the appropriate code fragment.3) If the previous bullet not works: Can You link that DLL staticly for debug purposes ?(At the load time with the export library). If You have a linking error when you try to use the same function that you have tried to load by GetProcAddress then the problem in the linking method.4) There is teoretically possible an error without NULL returning but I NOT BELIEVE IN THAT POSSIBILITY. It should be the last possible assumption.Best wishes, Sergey
0
 

Author Comment

by:tlsoftware
ID: 1162915
Ok I got it working; thanx for the help!  It was the name mangling in GetProcAddress.  The LoadLibrary function was actually working (but still returned error 126 which was misleading).  So I feel dumb.  Anyways thanx for the help!
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

717 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