The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Does the CLR really call CoInitializeEx on the first call to unmanaged code, even if you don't deal with COM at all and are just calling native code via p/invoke?
Mar 16, 2015
Post comments count 0
Post likes count 0

Does the CLR really call CoInitializeEx on the first call to unmanaged code, even if you don't deal with COM at all and are just calling native code via p/invoke?

Raymond Chen
Raymond Chen

Some time ago, I called out this part of the documentation regarding managed and unmanaged threading: On the first call to unmanaged code, the runtime calls Co­Initialize­Ex to initialize the COM apartment as either an MTA or an STA apartment. You can control the type of apartment created by setting the System.Threading.ApartmentState property on the thread to MTA, STA, or Unknown. Commenter T asks, "Does it do this even if you don't deal with COM at all and call native code through a P/Invoke?" Well, the documentation says it does, and we can confirm with an experiment: Run this program with...

Debugging walkthrough: Access violation on nonsense instruction, episode 2
Mar 13, 2015
Post comments count 0
Post likes count 0

Debugging walkthrough: Access violation on nonsense instruction, episode 2

Raymond Chen
Raymond Chen

Dueling debuggers.

Under what conditions will the IUnknown::AddRef method return 0?
Mar 12, 2015
Post comments count 0
Post likes count 0

Under what conditions will the IUnknown::AddRef method return 0?

Raymond Chen
Raymond Chen

When it's lying.

Dubious security vulnerability: Copying a program and running the copy
Mar 11, 2015
Post comments count 0
Post likes count 0

Dubious security vulnerability: Copying a program and running the copy

Raymond Chen
Raymond Chen

Code execution results in code execution.

The more times you use the word "simply" in your instructions, the more I suspect you don't know what that word means
Mar 10, 2015
Post comments count 0
Post likes count 0

The more times you use the word "simply" in your instructions, the more I suspect you don't know what that word means

Raymond Chen
Raymond Chen

I was helping somebody look up how to enable frobbing for widgets, and I found one set of instructions on a blog somewhere. To be honest, this happened long enough ago that I forgot what it was exactly, but here's something that captures the general spirit: First, check whether your widget supports frobbing. To do this, simply run this command where is the voodoo code for your widget. It will say "frob supported" if your widget supports frobbing. If you don't know your widget's voodoo code, you can get a list of the voodoo codes and enchantment numbers for all the widgets connected to your computer by s...

How can I programmatically resize a listview column to fit its contents?
Mar 9, 2015
Post comments count 0
Post likes count 0

How can I programmatically resize a listview column to fit its contents?

Raymond Chen
Raymond Chen

ListView_SetColumnWidth.

A question about the FileTimeToLocalFileTime function turned out to be something else
Mar 6, 2015
Post comments count 0
Post likes count 0

A question about the FileTimeToLocalFileTime function turned out to be something else

Raymond Chen
Raymond Chen

Negative time.

Modifying the CS_NOCLOSE style does affect all windows of the class, just not necessarily in an immediately noticeable way
Mar 5, 2015
Post comments count 0
Post likes count 0

Modifying the CS_NOCLOSE style does affect all windows of the class, just not necessarily in an immediately noticeable way

Raymond Chen
Raymond Chen

It's there, you just can't see it.

Why are the dimensions of a maximized window larger than the monitor?
Mar 4, 2015
Post comments count 0
Post likes count 1

Why are the dimensions of a maximized window larger than the monitor?

Raymond Chen
Raymond Chen

So you don't see the borders.