Solved

What does LoadLibrary really return on Error?

Posted on 1997-04-11
2
1,213 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
[X]
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
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Title # Comments Views Activity
repeatSeparator  java  challenge 13 59
fizzArray  challenge 1 115
fizzArray2 challenge 1 112
sumHeights  challenge 17 83
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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