Showing results for Code - The Old New Thing

Mar 24, 2005
0
0

Pointers to virtual functions with adjustors

Raymond Chen
Raymond Chen

As a mental exercise, let's combine two mind-numbing facts about pointers to member functions, namely that all pointers to virtual functions look the same and that pointers to member functions are very strange animals. The result may make your head explode. Consider: Here, the variable consists of a code pointer and an adjustor. The code p...

Code
Mar 23, 2005
0
0

Why does the debugger show me the wrong virtual function?

Raymond Chen
Raymond Chen

Pointers to virtual functions all look basically the same and therefore, as we learned last time, all end up merged into a single function. Here's a contrived example: If you take a look at and you'll see that the point to the same function: That's because the virtual functions and are both stored in the same location relative to the re...

Code
Mar 22, 2005
0
0

Why does the debugger show me the wrong function?

Raymond Chen
Raymond Chen

Often you'll be minding your own business debugging some code, and you decide to step into one function and the debugger shows that you're in some other function. How did that happen? You then step through code that does something like this: And when you step into the call to you find yourself in . What happened? What happened is that the...

Code
Mar 17, 2005
0
0

Your exception handler can encounter an exception

Raymond Chen
Raymond Chen

Consider the following code, written in C# just for kicks; the problem is generic to any environment that supports exception handling. Some time later, you find yourself facing an assertion failure from claiming that you are destroying the document while there are still active plugins. But there is your call to , and it's in a block, and the ...

Code
Mar 10, 2005
0
0

Why does SystemParametersInfo hang when I pass the SPIF_SENDCHANGE flag?

Raymond Chen
Raymond Chen

If you pass the flag to the function, it will broadcast the message with the wParam equal to the system parameter code you passed. For example, if you call then the system will broadcast the message If there is a window that isn't responding to messages, then this broadcast will hang until that unresponsive window finally resumes respon...

Code
Mar 9, 2005
0
0

Using SystemParametersInfo to access user interface settings

Raymond Chen
Raymond Chen

The function gives you access to a whole slew of user interface settings, and it is the only supported method for changing those settings. I'm not going to list every single setting; go read the list yourself. Here are some highlights: Here are some control panel settings. Notice that when using the SPI_SET* commands, you also have to choo...

Code
Mar 7, 2005
0
0

A timed context menu

Raymond Chen
Raymond Chen

This is sort of in the same spirit as our previous exercise in writing a timed message box, but this is much easier. Here, we use the handy-dandy message to get us out of menu mode. Before displaying the menu, we set a timer. (And we use a thread timer because we don't own the window and therefore don't know what timer IDs are safe to use.)...

Code
Mar 4, 2005
0
0

Modality, part 8: A timed MessageBox, the better version

Raymond Chen
Raymond Chen

A few days ago, we saw a simple version of a timed message box which had a limitation that it could be used from only one thread at a time. Today we'll work to remove that limitation. As you may recall, the reason why it could be used from only one thread at a time was that we kept the "Did the message box time out?" flag in a global. To fix i...

CodeModality
Mar 3, 2005
0
0

The bonus window bytes at GWLP_USERDATA

Raymond Chen
Raymond Chen

The window manager provides a pointer-sized chunk of storage you can access via the constant. You pass it to the function and the function to read and write that value. Most of the time, all you need to attach to a window is a single pointer value anyway, so the free memory in is all you need. Note that this value, like the other window ext...

Code
Mar 2, 2005
0
0

The scratch window

Raymond Chen
Raymond Chen

Sometimes you need a quick and dirty window and you don't want to go through all the hassle of registering a class for it. For example, you might need a window to do a brief snippet of DDE, or you just need a window to own a message box. To save yourself the trouble of registering a class for every single weenie thing you might need a window for...

Code