Showing tag results for Code

Dec 12, 2014
Post comments count0
Post likes count1

Detecting whether a SID is well-known SID

Raymond Chen

You might think that the function would tell you whether a SID is well-known, but it doesn't. Rather, it tells you whether a SID exactly matches the well-known SID you specified. For example, you can ask, "Is this the Authenticated Users SID?" or "Is this the Everyone SID?" But you can't ask, "Is this any type of well-known SID?" I guess you co...

Code
Dec 11, 2014
Post comments count0
Post likes count1

What states are possible in a DRAWITEMSTRUCT structure?

Raymond Chen

The structure has an member which contains a number of bits describing the state of the item being drawn. How do those states map to the underlying control? Most of the states are rather obvious. For a list box item to be selected, it means that the item is part of the selection. But what does selected mean for a button? Since people like table...

Code
Dec 10, 2014
Post comments count0
Post likes count1

If you get a procedure address by ordinal, you had better be absolutely sure it's there, because the failure mode is usually indistinguishable from success

Raymond Chen

A customer reported that the function was behaving strangely. We have this code in one of our tests: Recently, this test started failing in bizarre ways. When we stepped through the code, we discovered that ends up calling instead of . The first time we try to test , we get stack corruption because has a different function prototype from...

Code
Dec 8, 2014
Post comments count0
Post likes count1

Creating double-precision integer multiplication with a quad-precision result from single-precision multiplication with a double-precision result

Raymond Chen

Suppose you want to multiply two double-word values producing a quad-word result, but your processor supports only single-word multiplication with a double-word result. For concreteness, let's say that your processor supports 32 × 32 → 64 multiplication and you want to implement 64 × 64 → 128 multiplication. (Sound like any processor you know?) Oh...

Code
Dec 5, 2014
Post comments count0
Post likes count1

Killing a window timer prevents the WM_TIMER message from being generated for that timer, but it doesn't retroactively remove ones that were already generated

Raymond Chen

Calling to cancel a window timer prevents messages from being generated for that timer, even if one is overdue. In other words, give this sequence of operations: no message is ever generated. Even though a timer became due during the , no timer message was generated during the sleep because timer messages are generated on demand, and nobody ...

Code
Dec 4, 2014
Post comments count0
Post likes count1

If my WM_TIMER handler takes longer than the timer period, will my queue fill up with WM_TIMER messages?

Raymond Chen

A customer was worried that they may have a problem with their message queue filling with messages. "If my handler takes longer than the timer period, will my queue fill up with messages?" As we should know by now, timer messages are generated on demand: The WM_TIMER message is a low-priority message. The Get­Message and Peek­Message ...

Code
Dec 3, 2014
Post comments count0
Post likes count1

What happens if I don't paint when I get a WM_PAINT message?

Raymond Chen

Suppose your window procedure doesn't paint when it gets a message. What happens? It depends on how you don't paint. If you have an explicit handler for the message that does nothing but return without painting, then the window manager will turn around and put a new message in your queue. "And try harder this time." Remember that the rules ...

Code
Dec 1, 2014
Post comments count0
Post likes count2

Counting array elements which are below a particular limit value using SSE

Raymond Chen

Some time ago, we looked at how doing something can be faster than not doing it. That is, we observed the non-classical effect of the branch predictor. I took the branch out of the inner loop, but let's see how much further I can push it. The trick I'll employ today is using SIMD in order to operate on multiple pieces of data simultaneously. Ta...

Code
Nov 28, 2014
Post comments count0
Post likes count2

A user's SID can change, so make sure to check the SID history

Raymond Chen

It doesn't happen often, but a user's SID can change. For example, when I started at Microsoft, my account was in the SYS-WIN4 domain, which is where all the people on the Windows 95 team were placed. At some point, that domain was retired, and my account moved to the REDMOND domain. We saw some time ago that the format of a user SID is T...

Code
Nov 27, 2014
Post comments count0
Post likes count1

Some light reading on lock-free programming

Raymond Chen

Today is a holiday in the United States, so I'm going to celebrate by referring you to other things to read. I'm going to start with a presentation by Bruce Dawson at GDC 2009, which is basically multiple instances of the question "Is this code correct?", and the answer is always "No!" Although the title of the talk is Lockless Programming in Game...

Code