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 6865205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:00:46+00:00 2026-05-27T03:00:46+00:00

Assuming that GetDC(hWnd) is called as the first instruction on WM_CREATE , for window

  • 0

Assuming that GetDC(hWnd) is called as the first instruction on WM_CREATE, for window hWnd, is it possible for GetDC() to return NULL?

I am concerned about the possibility of GetDC() failing due to lack of resources. When that happens should I check for errors? And what should I do if the call fails? Do the Win32 API function raise exceptions or should I raise exceptions?

  • 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-05-27T03:00:46+00:00Added an answer on May 27, 2026 at 3:00 am

    GetDC() can indeed fail, no matter when or where you call it. You ought to take a rather pessimistic view when dealing with the API and be prepared for any API function to fail. As you suggest, one possible reason for failure is exhaustion of system resources, e.g. kernel handles, GDI objects etc.

    So you should always check for errors. And not just GetDC(), every single call to an API function should have its return value checked.

    The Windows API does not signal errors by raising exceptions. Instead the errors are always signalled through the values returned by the API function. You need to consult the documentation to understand how each individual function reports errors.

    If you encounter a failure in a GDI function like GetDC() then there’s not a lot you can do. In the scenario you describe I would log the error or report it to the user, and then terminate execution. There’s generally no recovery from a failure of GetDC().

    The pain of checking for errors every time an API function is called is one of the reasons why we have so many frameworks that wrap the low level API. A good framework will do the error checking for you and convert any errors into exceptions. Using a good framework allows you to concentrate on the normal flow of execution and not littering your code with handling code for exceptional cases.

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

Sidebar

Related Questions

Assuming that it's even possible, what would be your recomendations to make a bundle
assuming that I know nothing about everything and that I'm starting in programming TODAY
Assuming that I have an variable like: int n = 23; it is possible
Assuming that a C# program uses only managed .NET code, is it possible to
Assuming that there's a table called tree_node , that has the primary key called
Assuming that it is possible to compress a file from within an NSIS script,
Assuming that T is an arbitrary type and we're talking about Objective-C. Then what
Assuming that I'm in a function that is called in a Timer on in
Assuming that writing nhibernate mapping files is not a big issue....or polluting your domain
Assuming that I want to use a hash as an ID instead of a

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.