John Lam 1997 — 2026

Some MC++ gotchas

I’ve been spending a lot of time the past few days writing MC++ code. During this period of time, I had the MC++ epiphany, and I publicly apologized for my premature dismissal of this wonderful technology. At the time, I just didn’t get it.

What prompted me to use MC++ was my need to use the unmanaged metadata API’s, which I can only access via class COM interfaces. I’m not using these API’s because of some bizarre C++ machismo, I’m using them because the current System.Reflection API’s are too limiting.

However, before you dive to far into MC++, there is one important gotcha: you cannot debug unmanaged pointers using VS.NET! Yes that’s right folks, you cannot inspect the values of unmanaged pointers. This means that you had better not have any bugs in your unmanaged code before you use MC++ to write the high-performance interop layer. If you do, you’re back to manly man debugging using OutputDebugString and friends.

One possible solution to this debacle is to create two separate projects. The first project compiles your unmanaged C++ code only, and uses a test driver like CppUnit to drive your test cases. The second project compiles your unmanaged C++ code and your MC++ wrapper classes. I suspect that most folks will have to use a technique similar to this until MS fixes this bug (or is it a by-design limitation? ;)