Showing tag results for Code

Feb 17, 2014
Post comments count0
Post likes count1

Writing automation to wait for a window to be created (and dismiss it)

Raymond Chen

Today's Little Program uses UI Automation to cancel the Run dialog whenever it appears. Why? Well, it's not really useful in and of itself, but it at least provides an example of using UI Automation to wait for an event to occur and then respond to it. Okay, let's see what's going on here. The program registers a delegate with UI automation w...

Code
Feb 14, 2014
Post comments count0
Post likes count1

Debugging: Diagnosing why malloc is failing

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 count1

What is this extra thread in my process?

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 count1

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

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 count1

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

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 count1

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

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 count1

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

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 count1

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

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 count1

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

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