An Overview of Managed/Unmanaged Code Interoperability

I promised I’d post this link on my blog.  PDC attendees can also find it on their Longhorn DVD (Disk #2).  It’s a document called “The Developer’s Guide to Migration and Interoperability in Longhorn: Alpha Patterns and Practices”.



I’m about to catch my flight for the PDC, but I wanted to archive the following before I go: In one of our session’s demos on Tuesday, I’ll be briefly mentioning C# code that determines whether a given file is a managed or unmanaged binary by inspecting its PE header.  Here is the C++ code it’s based…


PDC Book Signing and Book Giveaway!

If you’re going to the PDC, and if you needed more incentive to attend Sonja’s and my session – Managed/Native Interop Best Practices and Common Pitfalls (That We Learned the Hard Way) – then look no further! During our session, we’ll be giving away up to 10 signed copies of .NET and COM: The Complete Interoperability…


GUID Generation and VB6 Binary Compatibility

When exposing managed types as COM types, your classes must have CLSIDs, your interfaces must have IIDs, and so on.  System.Runtime.InteropServices provides a custom attribute (GuidAttribute) that enables you to be explicit about these GUIDs.  But the CLR also has a reasonable algorithm for generating GUIDs on-the-fly, so you normally don’t need to be explicit…


Tech License Plates

Many people know about Don’s infamous IUNKNWN and INFOSET license plates, but recently I’ve been noticing more technology-inspired license plates around town.  Just the other day at the grocery store, I saw a car with a GUID license plate.  And not that long ago I saw INT3 on one car and FFFF00 on another (bright yellow)…


CLR SPY and Customer Debug Probes: The QueryInterface Failure Probe

It has taken awhile, but with this entry I will have described all 11 probes that exist in v1.1 of the CLR. When an RCW queries its underlying COM object for a specific interface, the QueryInterface call could fail for a variety of reasons.  The QueryInterface Failure probe doesn’t report every failed QI call as…


Suggestions for future CDPs?

In my next blog entry, I’ll explain the 11th and final Customer Debug Probe (CDP) that exists in the v1.1 product.  But for the next version of the product (code-named Whidbey), we’re looking at adding additional probes, and not just in the area of Interop.  The goal is to help you find, prevent, and/or diagnose…


Quiz: Searching in a managed array

Sorry for my recent lack of blogging.  There’s been a lot going on these days! As the banner on my blog now indicates, you’ll be able to catch me at two upcoming conferences.  As with TechEd in June, Sonja Keserovic and I will be giving an Interop presentation at this year’s PDC in October.  This…


CLR SPY and Customer Debug Probes: The Thread Changing Apartment State Probe

The last blog touched on apartment states of managed threads, which the CLR tracks for COM interoperability purposes.  But if an application changes the apartment state of a thread being tracked by the CLR (via unmanaged code or direct calls to CoUninitialize/CoInitialize), the runtime won’t be aware of this change.  Its information for that thread…


Gotcha with STAThreadAttribute and Managed C++

Managed thread objects have an ApartmentState property that can be set to STA or MTA.  But setting this property on the main thread doesn’t work reliably because the CLR might set the apartment state to MTA (by calling CoInitializeEx(NULL, COINIT_MULTITHREADED)) before your first line of code executes.  And once a thread’s apartment state has been…