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

The Archive Base Latest Questions

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

I spent a whole day looking for a bug caused by wrongly passing Windows

  • 0

I spent a whole day looking for a bug caused by wrongly passing Windows PHANDLE type to a function expecting HANDLE!!! I was expecting the VC++ 2010 compiler to catch such a simple and obvious type mismatch error. However, it didn’t. It just didn’t.

On a closer look, HANDLE is defined as void pointer in winnt.h and so PHANDLE is just void pointer pointer. Since anything can be passed to void * or void ** so PHANDLE and HANDLE mismatch can’t be warned by the compiler.

Is there anyway to avoid such a problem. I don’t know how many other Windows types are typedef’ed as void *. Are there any strategies to avoid such errors?

For example, the following compiled without any error in VC++ 2010, although the function is called by wrong pointer types. And, it is not obvious the pitfall is there unless one knows HANDLE (or any other Windows types) is a void pointer:

void f1 (HANDLE h) {
  printf("%x",h);
}

int _tmain(int argc, _TCHAR* argv[])
{
  PHANDLE ph=NULL;
  int c=0;

  f1(ph);
  f1(&c);
  return 0;
}
  • 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-26T04:17:34+00:00Added an answer on May 26, 2026 at 4:17 am

    The way to think of HANDLE is as the base type for all handles, such as HWND,HDC etc. Because C doesn’t support the concept of a base type they had to make it a void*.

    In most cases your app should be compiled with the STRICT flag set. This will ensure that all specific handles are actually based off of structures and so you won’t have any issues. However, if you do write a method that works with a general HANDLE then you’re going to have to be careful!

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

Sidebar

Related Questions

intro : I spent whole day looking why my processing operation is so so
I've spent a whole day on this already without figuring it out. I'm hoping
I have spent the whole day trying to make a script which on submit
I've spent whole day on this problem and still have no idea how to
I spent a whole day trying to process some files with backslashes and spaces
I've spent a whole day searching for a solution on how to get wsgen
When I call print_token() my app crashes. I spent the whole day trying to
I am getting 500 Internal error with Apache and FastCGI. Spent the whole day
I have spent the whole day trying to make my application use threads but
Ok, I have just spent the whole day playing with DomDocument and creating some

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.