Showing tag results for Code

Feb 21, 2014
Post comments count0
Post likes count1

How can I make sure my program is launched only from my helper program and no other parent?

Raymond Chen
Raymond Chen

Say you have a collection of programs which work together. One of them is the "master" program that runs the show, and it has a bunch of "assistant" programs that it launches to accomplish various subtasks. These assistants are not meant to be run by themselves; they are meant to be run only by the master program. How do you design the assistant so...

Code
Feb 20, 2014
Post comments count0
Post likes count1

What is the programmatic equivalent to unchecking the box to prevent a file from having its contents indexed?

Raymond Chen
Raymond Chen

A customer wanted to know how they could write a program that automatically checked and unchecked the box that appears on a file's property sheet on the General tab, clicking the Advanced button, and then checking or unchecking the item whose name keeps changing: The checkbox maps to the file attribute formally known as , and informally known as...

Code
Feb 19, 2014
Post comments count0
Post likes count1

When will the static control automatically delete the image loaded into it, and when is it the responsibility of the application?

Raymond Chen
Raymond Chen

If you create a static control with initial contents (for example, by creating a or control in a dialog template), then the static control will load the contents upon creation and destroy the contents upon destruction. So at least in the case where you don't touch the static control, things will work automatically. But once you touch it, thing...

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