Solved

What does LoadLibrary really return on Error?

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

9 Experts available now in Live!

Get 1:1 Help Now