The Old New Thing

Can OANOCACHE be used for non-debug purposes?

Friday asks whether OANOCACHE can be used for non-debug purposes, say to improve stability and/or speed. You can try, but it's not recommended. For one thing, it probably damages stability, because there are many applications out there which unwittingly rely on the BSTR cache to protect them from heap corruption bugs. The Windows team has ...

Don't try to allocate memory until there is only x% free

I have an ongoing conflict with my in-laws. Their concept of the correct amount of food to have in the refrigerator is "more than will comfortably fit." Whenever they come to visit (which is quite often), they make sure to bring enough food so that my refrigerator bursts at the seams, with vegetables and eggs and other foodstuffs crammed into ...

How do I print non-error messages during compilation?

Commenter Worf remarked, "My one wish is that would be supported." I always find it interesting when people say "I wish that Microsoft would stop following standards," since the directive is nonstandard. The Microsoft C/C++ compiler implements the feature in a method compatible with the standard, namely via a directive. If you ...

Why did HeapFree fail with ERROR_POSSIBLE_DEADLOCK?

A customer reported that they were receiving some assertion failures because the function was failing with what they believed to be a valid heap block, and the function reported that the reason for failure was . What's going on? One of my colleagues asked the psychic question, "Is the process exiting?" "Why yes, in fact it is. How did you ...

When DLL_PROCESS_DETACH tells you that the process is exiting, your best bet is just to return without doing anything

When the function receives a reason code of , the increasingly-inaccurately-named parameter to is used to indicate whether the process is exiting. And if the process is exiting, then you should just return without doing anything. No, really. Don't worry about freeing memory; it will all go away when the process address space is destroyed...

Creating context menus on menus

Last week we looked at menu drag/drop. Another little-used menu feature added in Windows 2000 is the ability to show context menus on menus. The message is and the flag is . Let's demonstrate with a simple program. Start with the scratch program, and add the function just so our context menu can do something. When we receive ...

Using the MNS_DRAGDROP style: Menu rearrangement

In order to do drag-drop rearrangement of menus, you need four things, most of which we already know how to do. Dragging an item out of a menu. Check. Dropping an item into a menu. Check. Connecting the drag with the drop. Rearranging menu items in response to the operation. Let's do step 4 first, just to mix things...

Using the MNS_DRAGDROP style: Dropping in

Last time, we looked at using the style for dragging items out of a menu. Today, we'll look at dropping them in. Take the program from last time and make the following additions. First, let's add a second item to the menu. Yes, I hard-coded another path. This is a demo, not production code. Anyway, it's time to hook up the message...

Using the MNS_DRAGDROP style: Dragging out

Windows 2000 introduced the menu style, which permits drag/drop operations in a menu. Nobody uses this style, probably because it's totally undiscoverable by the end-user. But I'll write a sample program anyway. Mind you, I knew nothing about the menu style until I started writing this entry. But I simply read the documentation, ...