Showing tag results for Code

Feb 3, 2012
Post comments count0
Post likes count1

The compatibility constraints of error codes, episode 2

Raymond Chen

A customer reported an incompatibility in Windows 7: If A: is a floppy drive and they call and there is no disk in the drive, the call fails with the error . Previous versions of Windows failed with the error . Both error codes are reasonable responses to the situation. "The module couldn't be found because the drive is not ready." Programs...

Code
Jan 27, 2012
Post comments count0
Post likes count1

Does mapping the same shared memory two times in a process lead to double the address space usage?

Raymond Chen

A customer designed a system which uses shared memory. Specifically, for each database file, they create a corresponding shared memory block of, say, 200MB. Multiple clients which connect to the same database file use the same shared memory block. Naturally, if two processes each access the same database file, each process will map the shared memor...

Code
Jan 25, 2012
Post comments count0
Post likes count1

How do I disable the fault-tolerant heap?

Raymond Chen

A while back, I linked to a talk by Silviu Calinoiu on the fault-tolerant heap. But what if you don't want the fault-tolerant heap? For example, during program development, you probably want to disable the fault-tolerant heap for your program: If the program is crashing, then it should crash so you can debug it! Method 1 is to disable the ...

Code
Jan 23, 2012
Post comments count0
Post likes count1

Can OANOCACHE be used for non-debug purposes?

Raymond Chen

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 for yea...

Code
Jan 18, 2012
Post comments count0
Post likes count1

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

Raymond Chen

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 every...

Code
Jan 13, 2012
Post comments count0
Post likes count1

How do I print non-error messages during compilation?

Raymond Chen

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 want ...

Code
Jan 6, 2012
Post comments count0
Post likes count1

Why did HeapFree fail with ERROR_POSSIBLE_DEADLOCK?

Raymond Chen

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 know?...

Code
Jan 5, 2012
Post comments count0
Post likes count1

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

Raymond Chen

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. Don...

Code
Jan 4, 2012
Post comments count0
Post likes count1

Creating context menus on menus

Raymond Chen

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 the me...

Code