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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:23:17+00:00 2026-05-26T18:23:17+00:00

Ok until now I’ve always coded with GCC so I am new to MSVC++

  • 0

Ok until now I’ve always coded with GCC so I am new to MSVC++ (and it’s errors). I compiled a minimal Win Api program with GDI plus. It compiles fine but closes with a runtime error almost as soon as it starts (I think the runtime error comes when the WM_PAINT message is called). Here’s what I see:
What I See

My code is nothing fancy it just displays a rectangle. ( It works fine when I do it with GDI but doesn’t work with GDI+).

My Code:

HDC hdc = GetDC(hwnd);

InvalidateRect(hwnd,NULL,FALSE);

ULONG_PTR token;
GdiplusStartupInput inp;
GdiplusStartup(&token,&inp,0);

Graphics g(hdc);
g.Clear(Color(0,0,0));
g.DrawRectangle(new Pen(Color(0,0,0)),10,10,100,100);

GdiplusShutdown(token);
ValidateRect(hwnd,NULL);

By debugging I found that the runtime error comes almost as soon as the Graphics g(hdc); constructor is called. I can’t find anything on google etc. I’m completely lost. Any help?

  • 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-26T18:23:18+00:00Added an answer on May 26, 2026 at 6:23 pm

    WinAPI functions always indicate success one way or another. You need to check if GetDC returned a valid handle. See the Return value section of GetDC. The access violations in the output also point towards an invalid pointer somewhere. If the DC is valid, check everything else. Make sure you pass pointers where an address is required etc.

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

Sidebar

Related Questions

Until now I've always used the ASP.NET MVC framework source for debugging ASP.NET MVC.
Until now, I was always working on my own for PHP-projects, but at the
Until now, I have always said that CakePHP is too bloated and slow. I
I'm new to Oracle (I've been using MySQL mainly until now) so this might
Until now I found two ways to run my program with maven3: $ mvn
this may be a simple question but until now I always created a web
Until now I have always specified the format of the response for actions using
Question: Until now, I didn't know LINQ was an ORM tool. I always saw
Until now I have always been constrained by one thing with jasper-reports. I can
Until now, my project had only .cpp files that were compiled into different binaries

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.