Api Problems Ccomobject Createinstance

CComObject::CreateInstance is a light weight method for creating instances of COM objects in your code. Unfortunately the design of the API makes it easy to introduce subtle errors into your code. The two problems are it encourages manually ref counting and the object initially has a ref count of 0. This means you must remember to AddRef before calling any other function. Neither of these ideas in themselves are bad but it leads to tedious, repetitive code that is too often done incorrectly.

Part Of Being A Good Programmer Is Learning Not To Trust Yourself

… and to actively guard against yourself.

Making Pinvoke Easy

I very excited to announce we recently released a tool I’ve been working on to MSDN that will greatly help with using PInvoke in managed code. The tool is called the “PInvoke Interop Assistant” and is included as part of a MSDN article on marshalling data for PInvoke and Reverse PInvoke scenarios.

Pipesinglereadernolock

Previously we discussed a multi-thread safe queue like data structure using locks as an internal synchronization mechanism. This time we’ll look at a version requiring no locks.

Pipesinglereader

Before we can get to building an Active Object implementation, there are some more primitive structures we need to define. Active Objects live on a separate thread where every call is executed in a serialized fashion on that thread. The next primitive will allow us to easily pass messages in the form of delegates from the caller to the background thread.