Solved

LoadLibrary

Posted on 1997-04-22
4
2,581 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.

910 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

25 Experts available now in Live!

Get 1:1 Help Now