Hosting Silverlight in C++
See the question and my original answer on StackOverflowI have tested the code project available here: http://www.codeproject.com/KB/atl/Host_Silverlight_In_ATL.aspx under Visual Studio 2010. Here is what's needed to make it work:
- load it under VS 2010 and convert it to VS 2010 (don't care about backupgs logs, etc...)
- remove the registration Post-Build Event ("$(TargetPath)" /RegServer), it's only used for registration of COM components inside the projet. You can also let that event and just forget about the error if you prefer.
- I had to do a small change in XcpControlHost.cpp.
Here is the change:
HRESULT CXcpControlHost::CreateXcpControl(HWND hWnd)
{
AtlAxWinInit();
CoInitialize(NULL); // add this line to initialize COM
...
}
And it works (I'm running Windows 7 with Silverlight 4).
This is really the way to go.
One remark though: In the sample, the author does not use the official xcpctrl.idl file available from here: http://msdn.microsoft.com/en-us/library/cc296246(VS.95).aspx . Instead he redefines all interfaces and GUID, and this is not needed. You can just add the xcpctrl.idl to a Visual Studio 2010 and compile, this will trigger the MIDL compiler that will create the 3 following files: xcpctrl_h.h, xcpctrl_i.c, xcpctrl_p.c. Once they are compiled, you can add them to the project.