Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2010 debugger in C++, meaning of "unused=???" or "unused=0"

Debugging in Visual Studio 2010 (C++, unmanaged), what is the information unused ??? or unused 0 supposed to mean? I have attached two screenshots, child is a HWND to an existing window.

I am also confused by the fact, that the HWND is sometimes displayed as "unused", sometimes as "0". When having a pointer referring to unallocated memory, I'd understand the situation, but in my particular case the window is already created and valid.

VS2010 unused=???

VS2010 unused=0

like image 305
Horst Walter Avatar asked Jun 26 '12 09:06

Horst Walter


People also ask

How do I disable debugger only my code?

To enable or disable Just My Code in Visual Studio, under Tools > Options (or Debug > Options) > Debugging > General, select or deselect Enable Just My Code.

How do I stop vs debugging?

To end a debugging session in Microsoft Visual Studio, from the Debug menu, choose Stop Debugging.

What is a debugger in C#?

Debugging is the process of finding errors during application execution. It does not mean syntax errors, with which the application cannot be compiled, but on logic errors. Logic errors can only be noticed during application execution. See the following method. private double Divide(double a, double b)

How do I keep debugging in Visual Studio?

In most languages supported by Visual Studio, you can edit your code in the middle of a debugging session and continue debugging. To use this feature, click into your code with your cursor while paused in the debugger, make edits, and press F5, F10, or F11 to continue debugging.


1 Answers

This goes back to the early nineties, back when there was just a HANDLE as a type to declare a handle of any Windows object. Which was a bug factory, programmers could fumble code and, say, pass a font handle where a window handle was required. So the STRICT macro was added later, it redeclared handle types so mixing produces a compiler error. Which looks like this in winnt.h, edited for content:

#ifdef STRICT
   typedef void *HANDLE;
   #define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name
#else
   typedef PVOID HANDLE;
   #define DECLARE_HANDLE(name) typedef HANDLE name
#endif

Example usage:

DECLARE_HANDLE(HWND);

The struct macro soup ensures that a HFONT can never be used where a HWND is expected when STRICT is turned on, it produces a type mismatch on the structure type.

You can now see where "unused" comes from. It is in fact unused, only Windows can create handle values. It is helpful in the debugger since it lets you look at the handle value, with 0 or -1 being a sure sign of trouble.

More about STRICT in this MSDN article.

like image 88
Hans Passant Avatar answered Sep 18 '22 22:09

Hans Passant