I have a C# WPF User Control. I want to load that on C++ MFC Dialog.
But the catch is, I do not want to use ActiveX Control.
I want the C# WPF User Control to be COM component and that COM component should be loaded on my other C++ MFC Dialog.
How can this be achieved?
What I have tried:
I created one C# WPF User Control as:
[ComVisible(true)]
[Guid("SomeGUID")]
public partial class UserControl1 : UserControl
{
}
Registered it using RegAsm.exe <mycsharpwpfusercontroldllname> /codebase /tlb and got the .TLB file out of it.
Later in my C++ MFC Dialog I imported that .TLB file and following is the OnInitDialog of my MFC Dialog.
virtual BOOL OnInitDialog() override
{
CDialogEx::OnInitDialog();
CoInitialize(nullptr);
HRESULT hr = m_spUserControl.CreateInstance(__uuidof(UserControl1));
if (SUCCEEDED(hr))
{
HWND hWndUserControl = m_spUserControl->GetHandle();
CWnd* pWnd = GetDlgItem(IDC_STATIC_USERCONTROL);
pWnd->Attach(hWndUserControl);
}
return TRUE;
}
But some how the above thing is not working.
My MFC dialog application is crashing. I tried to debug, but it is not providing any proper information.