Windows Phone 7 and native C++/CLI

c++/cli can theoretically be used with WPF/Silverlight using the trick of replacing the C# generated from the XAML with a macro definition that can be used inside the main class in a code behind file. I worked out this technique but haven’t had the motivation to take it beyond theory – I’m quite happy mixing languages.

As far as using c++/cli in a pure safe mode for your logic code, this may still not be possible but I’d love to hear how someone goes trying it now. Whilst researching it for Silverlight back in 2008 I found this daunting silverlight forum comment:

I just gave Silverlight&C++ it a try by compiling the MSIL from my C++ project into a Silverlight-compatible DLL. The good news: it works, and you can call this code from a Silverlight project. The bad news: The C++ compiler apparently uses MSIL instructions that Silverlight disallows.

So, if you try this, even with the simplest of programs, you’ll almost immediately get the exception “Operation could destabilize the runtime.” To me, this makes it seem less likely that we’ll see Silverlight for C++ soon, as the compiler will need to behave quite a bit differently.

Leave a Comment