Showing results for Code - The Old New Thing

Feb 14, 2014
Post comments count0
Post likes count0

Debugging: Diagnosing why malloc is failing

Raymond Chen
Raymond Chen

A customer had some code which was experiencing memory allocation failures when calling (which maps to ). The function returns , and reports . However, there was still plenty of memory free: The customer was continuing their investigation but was looking for some pointers since the bug took a day to emerge. Could it be heap fragmentation? (The...

Code
Feb 12, 2014
Post comments count0
Post likes count0

What is this extra thread in my process?

Raymond Chen
Raymond Chen

A customer liaison asked: After applying Service Pack 2 to Windows Server 2003, my customer found that a simple MFC application (just using the template, no customization) has two threads when it is supposed to have only one. After five minutes, one of the threads exits. This doesn't happen on Windows Server 2003 RTM or Windows Server 2003...

Code
Feb 10, 2014
Post comments count0
Post likes count0

Execute a file as if it were a program, even though its extension is not EXE

Raymond Chen
Raymond Chen

Today's Little Program executes a file as if it were a program, even though its extension is not EXE. The idea here is to prevent somebody from running your program by accident, so you give it an extension like . This is great for preventing somebody from running the program by mistake, but how do you do it on purpose? We're merely using the ...

Code
Feb 7, 2014
Post comments count0
Post likes count0

VirtualLock locks your memory into the working set, even if your threads are blocked

Raymond Chen
Raymond Chen

Today, a correction to an earlier article on . When you lock memory with , it will remain locked even if all your threads are blocked. As noted in the Follow-up section at the end of the referenced article, the behavior of the operating system never changed. Virtually-locked pages were never unlocked in practice. What changed is that an implement...

Code
Feb 6, 2014
Post comments count0
Post likes count0

If an asynchronous I/O completes synchronously, is the hEvent in the OVERLAPPED structure signaled anyway?

Raymond Chen
Raymond Chen

Yes. When an I/O completes (whether synchronously or asynchronously), the event is signaled and completion status notifications are queued. The function can be used to wait on an I/O that has already completed; it will merely return immediately. If you ask whether the I/O has completed, and the I/O completed synchronously, it will correctly repo...

Code
Feb 3, 2014
Post comments count0
Post likes count0

How can I make a WNDPROC or DLGPROC a member of my C++ class?

Raymond Chen
Raymond Chen

Continuing my discussion of How can I make a callback function a member of my C++ class? Common special cases for wanting to use a member function as a callback function are the window procedure and its cousin the dialog procedure. The question, then, is where to put the reference data. Let's start with window procedures. The function and it...

Code
Jan 31, 2014
Post comments count0
Post likes count0

Non-psychic debugging: If somebody's complaining that a collection should be empty but isn't, you might want to see what's in there

Raymond Chen
Raymond Chen

A programmer on the GHI team (yes, the same GHI team) reported that they were hitting an assertion failure using an internal library and asked for help debugging it. "Can somebody help me figure out which factory it is that did not get unregistered?" I didn't work on this internal library, but on the other hand I'm not afraid to look inside....

Code
Jan 30, 2014
Post comments count0
Post likes count0

Can process IDs be greater than 64000? Because we're seeing process IDs greater than 64000

Raymond Chen
Raymond Chen

A customer asked what to me was a very strange question. Can process IDs be greater than 64000? Because we're seeing process IDs greater than 64000. This is a strange question because the answer is right there: You're seeing process IDs greater than 64000 with your very own eyes. Do you doubt the evidence right there in front of you? It's li...

Code
Jan 29, 2014
Post comments count0
Post likes count0

One of my favorite error codes: Optional parameter missing

Raymond Chen
Raymond Chen

The error Optional parameter missing sounds awfully paradoxical, doesn't it. I mean, if the parameter is optional, why are you complaining that it's missing? This KB article explains why, specifically, the part that says, "If a parameter is omitted, the calling program must…". For those who don't want to click through, here's the deal: Me...

Code