Showing tag results for Code

Oct 1, 2014
Post comments count0
Post likes count1

You can name your car, and you can name your kernel objects, but there is a qualitative difference between the two

Raymond Chen
Raymond Chen

A customer reported that the appeared to be unreliable. We have two threads, one that waits on an event and the other that signals the event. But we found that sometimes, signaling the event does not wake up the waiting thread. We have to signal it twice. What are the conditions under which will ignore a signal? // cleanup and error checkin...

Code
Sep 29, 2014
Post comments count0
Post likes count1

Simulating media controller buttons like Play and Pause

Raymond Chen
Raymond Chen

Today's Little Program simulates pressing the Play/Pause button on your fancy keyboard. This might be useful if you want to write a program that converts some other input (say, gesture detection) into media controller events. One way of doing this is to take advantage of the function, since the default behavior for the message is to pass the m...

Code
Sep 26, 2014
Post comments count0
Post likes count1

Marshaling won't get in your way if it isn't needed

Raymond Chen
Raymond Chen

I left an exercise at the end of last week's article: "Why is the error raised only sometimes?" COM subscribes to the principle that if no marshaling is needed, then an interface pointer points directly at the object with no COM code in between. If the current thread is running in a single-threaded apartment, and it creates a COM object with t...

Code
Sep 25, 2014
Post comments count0
Post likes count1

If a process crashes while holding a mutex, why is its ownership magically transferred to another process?

Raymond Chen
Raymond Chen

A customer was observing strange mutex ownership behavior. They had two processes that used a mutex to coordinate access to some shared resource. When the first process crashed while owning the mutex, they found that the second process somehow magically gained ownership of that mutex. Specifically, when the first process crashed, the second proces...

Code
Sep 22, 2014
Post comments count0
Post likes count1

Receiving a notification any time the selection changes in an Explorer window

Raymond Chen
Raymond Chen

Today's Little Program merely prints a message whenever the user changes the selection on the desktop. I chose the desktop for expediency, since it saves me the trouble of coming up with a way for the user to specify which Explorer window they want to track. Also, all I do is print a message saying "Selection changed!"; actually getting the select...

Code
Sep 18, 2014
Post comments count0
Post likes count1

The stream pointer position in IDataObject::GetData and IDataObject::GetDataHere is significant

Raymond Chen
Raymond Chen

An oft-overlooked detail of the and methods is the position of the stream pointer when the result is a stream. These rules are buried in the documentation, so I'm going to call them out louder. Let's look at first. If returns a stream, then the stream pointer must be positioned at the end of the stream before the stream is returned. In ot...

Code
Sep 15, 2014
Post comments count0
Post likes count1

Enumerating all the ways of making change

Raymond Chen
Raymond Chen

Today's Little Program enumerates all the ways of making change for a particular amount given a set of available denominations. The algorithm is straightforward. To make change for a specific amount from a set of available denominations, you can take one denomination and decide how many of those you want to use. Then use the remaining denominati...

Code
Sep 8, 2014
Post comments count0
Post likes count1

Piping to notepad

Raymond Chen
Raymond Chen

In honor of NotepadConf's new KickStarter video, today's Little Program takes its stdin and puts it in a Notepad window. The comments pretty much lay out the steps. The part that may not be obvious is the part that deals with UI Automation: We take the main Notepad window, then ask UI Automation to find Document element inside it. From that ...

Code
Sep 5, 2014
Post comments count0
Post likes count1

You can use a file as a synchronization object, too

Raymond Chen
Raymond Chen

A customer was looking for a synchronization object that had the following properties: Can be placed in a memory-mapped file. Can be used by multiple processes simultaneously. Bonus if it can even be used by different machines simultaneously. Does not leak resources if the file is deleted. It turns out there is already a synchronization ob...

Code