Solved

LoadLibrary

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

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

12 Experts available now in Live!

Get 1:1 Help Now