Solved

What does LoadLibrary really return on Error?

Posted on 1997-04-11
2
1,190 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 20 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 94
Hibernate methods 2 71
twoTwo  challenge 35 101
zeroFront challenge 7 96
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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