Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

What does LoadLibrary really return on Error?

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 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