Showing tag results for Code

Nov 28, 2014
Post comments count0
Post likes count1

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

Raymond Chen
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 count0

Some light reading on lock-free programming

Raymond Chen
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
Nov 24, 2014
Post comments count0
Post likes count0

The crazy world of stripping diacritics

Raymond Chen
Raymond Chen

Today's Little Program strips diacritics from a Unicode string. Why? Hey, I said that Little Programs require little to no motivation. It might come in handy in a spam filter, since it was popular, at least for a time, to put random accent marks on spam subject lines in order to sneak past keyword filters. (It doesn't seem to be popular any more.)...

Code
Nov 21, 2014
Post comments count0
Post likes count0

Is it wrong to call SHFileOperation from a service? Revised

Raymond Chen
Raymond Chen

My initial reaction to this question was to say, "I don't know if I'd call it wrong, but I'd call it highly inadvisable." I'd like to revise my guidance. It's flat-out wrong, at least in the case where you call it while impersonating. The registry key is bound to the current user at the time the key is first accessed by a process: The mapping...

Code
Nov 20, 2014
Post comments count0
Post likes count0

A library loaded via LOAD_LIBRARY_AS_DATAFILE (or similar flags) doesn't get to play in any reindeer module games

Raymond Chen
Raymond Chen

If you load a library with the flag, then it isn't really loaded in any normal sense. In fact, it's kept completely off the books. If you load a library with the , , or flag (or any similar flag added in the future), then the library gets mapped into the process address space, but it is not a true module. Functions like , , and will not see th...

Code
Nov 17, 2014
Post comments count0
Post likes count0

How do I enumerate drives the same way that the NET USE command does?

Raymond Chen
Raymond Chen

If you use the Remote Desktop Connection client to connect to another computer, you have the option of making your local drives available to the remote computer. A customer wanted to know how to enumerate all the drives on the local machine. The were able to get the volumes mapped to drive letters, but they also wanted to get the redirected dri...

Code
Nov 13, 2014
Post comments count0
Post likes count0

When does GetTickCount consider the system to have started?

Raymond Chen
Raymond Chen

The and functions return "the number of milliseconds that have elapsed since the system was started." (The 32-bit version wraps around after around 50 days.) But when exactly is the system considered to have started? Is it when power is applied to the computer? When the BIOS completes POST? When the user picks the operating system from the boot m...

Code
Nov 12, 2014
Post comments count0
Post likes count0

How can I wait until all startup applications have finished launching?

Raymond Chen
Raymond Chen

A customer wanted to know how to detect that all startup applications have finished launching. They wanted to wait until everything settled down before proceeding with some task. What if two programs did this? Suppose two programs both wanted to detect that all startup applications have finished launching. Each one would sit there waiting for the...

Code
Nov 10, 2014
Post comments count0
Post likes count0

Kicking around a function that formats stuff

Raymond Chen
Raymond Chen

Today's "Little Program" is really a "Little Puzzle" that got out of hand. This started out as a practical question: This code fragment screams out for some sort of simplification. (I've changed the names of the classes.) Clearly, the pattern is Everything here is pretty straightforward, except for the part. Can we write a function that t...

Code
Nov 7, 2014
Post comments count0
Post likes count0

Why does an attempt to create a SysLink control in my plug-in sometimes fail?

Raymond Chen
Raymond Chen

A customer had written a plug-in for some application, and they found that their plug-in was unable to create a SysLink control via the function. The same code in a standalone application works fine, but when the code is placed in their plug-in, the code fails. Debugging showed that the call to succeeded, but the call failed with "Cannot find w...

Code