views:

97

answers:

2

I want to use WPF in an app. I want to write it in C++. Does the application have to be managed? I know that I can mix managed with unmanaged. I'm wondering if I can have the whole application be unmanaged.

+1  A: 

As you already know, you can mix managed and unmanaged via interop; however, WPF runs on the CLR.

Here is an article on the Web where some folks speculate about a future unmanaged version:

http://neilmosafi.blogspot.com/2008/07/unmanaged-version-of-wpf-coming.html

Here is an additional reference on WPF/native interop, should you choose to go that route:

http://msdn.microsoft.com/en-us/library/ms742522.aspx

kbrimington
Readers should note that the speculation in your first link was based on a description of PDC08 sessions that turned out to be about MIL. In the past two years I have not heard anything else or any other speculation that MIL might be made into a public API. Even if it were, it wouldn't be WPF since MIL includes only low-level primitives.
Ray Burns
Thanks, @Ray. That's good information.
kbrimington
+5  A: 

You can easily develop 99% of your WPF application in unmanaged code, but making it 100% unmanaged is quite difficult.

WPF classes don't have a Guid attribute, so they won't work with COM. So constructing WPF objects such as Button and Window with 100% unmanaged code requires one of the unmanaged CLR APIs. The Hosting API is probably the easiest, but it is still quite a bit of work.

If you are willing to accept 99% unmanaged code, just compile your application with the /clr option and use IJW to instantiate WPF objects and call methods like Application.LoadComponent.

Also note that WPF binding to unmanaged objects requires that those objects fully support COM including IDispatch.

Ray Burns