Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:52:04+00:00 2026-06-15T21:52:04+00:00

Is there some kind of NULL Handle in Windows? If I create a bmp

  • 0

Is there some kind of NULL Handle in Windows? If I create a bmp via CreateCompatibleBitmap() and delete it via DeleteObject() and want to use move semantics, I want to make sure that the bitmap is not destroyed. Hence I have to set the HBITMAP to a value that is secure to delete. Like delete nullptr.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:52:05+00:00Added an answer on June 15, 2026 at 9:52 pm

    Bad news first. For historic reasons, there is no generally valid “invalid handle” value in the Windows API. Different subsystems in Windows consider either NULL or INVALID_HANDLE_VALUE as the invalid handle value (both for returning an invalid handle value and for taking one). Related article on Old New Thing.

    However, the good news is that although you still need to be prepared for unexpected return values (unless you dig through the documentation for every single function you use), providing either invalid value still always “works” in practice.
    You might not have used the correct designated “invalid” value, but it’s still invalid, and thus the function will fail. Your application will not crash, there are no negative consequences other than having wasted a few CPU cycles.

    Therefore, go ahead and use NULL (or nullptr), you’re good with that. If nothing else, it’s intuitive for someone reading your code later. In your concrete example, it’s also the correct thing, since GDI functions assume NULL as invalid.

    You can pretty much rely that both NULL and INVALID_HANDLE_VALUE are invalid values. Although I’m not aware of a requirement (as in, explicitly stated in the documentation) that a valid HANDLE must be non-zero, in practice they always are. I’m willing to bet you will not find a handle with the value zero, ever (just try and use Sysinternals’ handle tool, no single process on your computer will probably have a handle lower than 20).

    But even assuming that NULL can be a valid handle value, you have to consider that some handles are already opened and closed even before main is called or global constructors are run, you really don’t have a choice. That means that assuming NULL could be a valid handle, and asssuming it was still valid at the time your program runs, the chance that this hypothetical handle is incidentially of a type compatible with the API function is very low.

    On the other hand, one might argue that an application might have (unsigned) -1 handles open, rendering INVALID_HANDLE_VALUE a valid value.

    Unless you are leaking handles, I cannot imagine how you would ever get that many open handles. But more importantly, long before hitting that number, you’ll probably run out of memory on a 64 bit system, and you’ll definitively run out of address space on a 32 bit system.
    If INVALID_HANDLE_VALUE being a valid handle ever becomes an issue, you have a much more serious problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some kind of software that I can feed uploaded images to and
Is there some kind of tool for creating user interfaces using ATL for C/C++?
Is there some kind of a shorthand fluent interface for creating a parameters dictionary
Is there some kind a engine for Json in the Zend framework, What I
Possible Duplicate: Is there a CSS parent selector? Is there some kind of .this
I was wondering if there exists some kind of indexer (in python language for
As far as I know there's some kind of Linux in the Chrome OS
I would like to know if there is some kind of special markup to
I would like to know if there is some kind of instanceof functionality in
Firstly, I was wondering if there was some kind of built in function that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.