Showing tag results for Code

Oct 15, 2014
Post comments count0
Post likes count1

The GetCurrentThread function is like a check payable to Bearer: What it means depends on who's holding it

Raymond Chen
Raymond Chen

The function returns a pseudo-handle to the current thread. The documentation goes into significant detail on what this means, but I fear that it may have fallen into the trap of providing so much documentation that people decide to skip it. Okay, so first of all, what is a pseudo-handle? a pseudo-handle is a sentinel value for that is not r...

Code
Oct 10, 2014
Post comments count0
Post likes count1

Some parts of an interface can change but others can't

Raymond Chen
Raymond Chen

When I wrote about asking the compiler to answer calling convention questions, some people were concerned about whether this was a reliable mechanism or whether it was relying on something that can change in the future. This is a special case of the question, "What parts of an interface can change, and what can't?" And it all boils down to comp...

Code
Oct 8, 2014
Post comments count0
Post likes count1

Standard handles are really meant for single-threaded programs

Raymond Chen
Raymond Chen

When I discussed the conventions for managing standard handles, Sven2 noted that I implied that you need to call with a new handle if you close the current handle and asked "Wouldn't it make more sense to call it the other way round? I.e., first set the new handle, then close the old one? It would ensure that any other thread that runs in paralle...

Code
Oct 6, 2014
Post comments count0
Post likes count1

Enumerating cyclical decompositions with Stirling numbers

Raymond Chen
Raymond Chen

This whole enumeration nightmare-miniseries started off with Stirling numbers of the second kind. But what about Stirling numbers of the first kind? Those things ain't gonna enumerate themselves! The traditional formulation of the recursion for Stirling numbers of the first kind (unsigned version, since it's hard to enumerate negative numbers)...

Code
Oct 2, 2014
Post comments count0
Post likes count1

In the red corner, EXCEPTION_INT_DIVIDE_BY_ZERO and STATUS_INTEGER_DIVIDE_BY_ZERO; and in the blue corner, EXCEPTION_INT_OVERFLOW and STATUS_INTEGER_OVERFLOW

Raymond Chen
Raymond Chen

The exception code (and its doppelgänger ) is raised, naturally enough, when the denominator of an integer division is zero. The x86 and x64 processors also raise this exception when you divide by , or more generally, when the result of a division does not fit in the destination. The division instructions for those processors take a 2N-bit...

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