Showing results for Code - The Old New Thing

Aug 16, 2013
Post comments count0
Post likes count0

If I signal an auto-reset event and there is a thread waiting on it, is it guaranteed that the event will be reset and the waiting thread released before SetEvent returns?

Raymond Chen
Raymond Chen

Let's go straight to the question: I have two programs that take turns doing something. Right now, I manage the hand-off with two auto-reset events. In Thread A, after it finishes doing some work, it signals Event B and then immediately waits on Event A. Thread B does the converse: When its wait on Event B completes, it...

Code
Aug 15, 2013
Post comments count0
Post likes count0

How do I control the order of the pages in property sheets from my shell extension?

Raymond Chen
Raymond Chen

A customer wanted to know whether a shell extension can control the order of the property sheet pages in a property sheet. The interface lets you add pages and replace pages, but nothing about rearranging them. Naturally a shell extension can control the relative order of its own pages (by changing in the order in which it calls ) but how can it...

Code
Aug 14, 2013
Post comments count0
Post likes count0

What's the point of letting you change the GCL_CBCLSEXTRA if it has no effect?

Raymond Chen
Raymond Chen

The documentation for the function mentions GCL_CB­CLS­EXTRA: Sets the size, in bytes, of the extra memory associated with the class. Setting this value does not change the number of extra bytes already allocated. What's the point of letting the application change a value if it has no effect? The class long grants access to the v...

Code
Aug 12, 2013
Post comments count0
Post likes count0

How do I convert a synchronous file handle into an asynchronous one?

Raymond Chen
Raymond Chen

Say you opened a file in synchronous mode, and then you realize that you want to issue asynchronous I/O on it, too. One way to do this is to call a second time with the , but this requires you to know the file name, and the file name may not be readily available to the function that wants to do the conversion, or it may not even be valid any long...

Code
Aug 9, 2013
Post comments count0
Post likes count0

Why does the CLR report a NullReferenceException even if the referenced access is not exactly the null pointer?

Raymond Chen
Raymond Chen

We saw some time ago that before invoking a method on an object, the CLR will generate a instruction to force a null reference exception to be raised if you are trying to invoke a method on a null reference. But why does the CLR raise a if the faulting address is almost but not quite zero? When run, this program raises a rather than an . ...

Code
Aug 8, 2013
Post comments count0
Post likes count0

On partially-constructed objects, additional remarks, not as interesting

Raymond Chen
Raymond Chen

Don't worry. Our long national nightmare of CLR week is almost over. I had originally planned to write an article about partially-constructed objects, but in the time since I queued up the topic (back in November 2005) to the time I got around to writing it up, I found that Joe Duffy had already written it for me! On partially-constructed ob...

Code
Aug 7, 2013
Post comments count0
Post likes count0

Weak references have no effect on object lifetime

Raymond Chen
Raymond Chen

The class lets you retain a reference to an object while still permitting the object to be garbage collected. When that happens, then the property is and the property is . (Related discussion.) Note, however, that weak references do not alter the decision of the garbage collector whether or not an object is garbage. It merely lets you observe ...

Code
Aug 6, 2013
Post comments count0
Post likes count0

The mysterious ways of the params keyword in C#

Raymond Chen
Raymond Chen

If a parameter to a C# method is declared with the keyword, then it can match either itself or a comma-separated list of um itselves(?). Consider: This program prints The first call to does not take advantage of the keyword and passes the array explicitly (formally known as normal form). The second call, however, specifies the integers d...

Code
Aug 5, 2013
Post comments count0
Post likes count0

Why does BitConverter.LittleEndian return false on my x86 machine?

Raymond Chen
Raymond Chen

Welcome to CLR Week 2013, returned from its two-year hiatus. A customer reported that when they checked with the debugger, reported even though they were running on an x86 machine, which is a little-endian architecture. The bytes are extracted in little-endian order, despite the claim that the machine is big-endian. "I don't get it." I d...

Code
Jul 29, 2013
Post comments count0
Post likes count0

A program for my nieces: The ABCs, part 4

Raymond Chen
Raymond Chen

Disabling autorepeat in my ABC program was largely sufficient to keep my nieces happy, given their instructions to press only one key at a time. Once in a while, though, they would hit the context menu key in the bottom right corner of the keyboard, and then they'd get stuck because they didn't know how to dismiss it. So let's disable that key ...

Code