Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What does LoadLibrary really return on Error?

Posted on 1997-04-11
2
Medium Priority
?
1,249 Views
Last Modified: 2013-11-20
In 16-bit land, ::LoadLibrary() returned HINSTANCE_ERROR (which has a value of 32) on error.  In 32-bit land, the help now says it returns NULL on error.  Is that true, or is this a documentation bug?  (I'm not having any problems, I'd just like to be sure before I change all my code...)
0
Comment
Question by:laleonard
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
rhgaracci earned 40 total points
ID: 1300978
I think the documentation is correct.  To be absolutely safe though, I would recommend using a macro definition to perform your validation.

#ifdef _WIN32
#define IS_VALID_HINSTANCE(hInst) ((hInst) != (HINSTANCE) NULL)
#else
#define IS_VALID_HINSTANCE(hInst) ((hInst) != HINSTANCE_ERROR)
#endif


0
 
LVL 1

Expert Comment

by:rhgaracci
ID: 1300979
You can use it as follows:

hinstLib = LoadLibrary(...);
if (IS_VALID_HINSTANCE(hinstLib)
{
   // do something
}

This should work as well

if (IS_VALID_HINSTANCE(hinstLib = LoadLibrary(...))
{
    // do something
}

If you find the documentation to be in error, you need only change the macro definition in one place!  It also can help to protect if the api changes in the future.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

876 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