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?

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 CoInitializeEx 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

Dueling debuggers.

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

When it's lying.

Dubious security vulnerability: Copying a program and running the copy

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

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?

ListView_SetColumnWidth.

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

Negative time.

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

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

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

So you don't see the borders.