我有一个 MFC 应用程序,其中包含一个 C++/CLI 项目,该项目调用
MFC::CWinFormsControl<MyWidget>::CreateManagedControl()
来创建用 C# 编写的控件。
这在 .Net Framework 4.6.1 下运行良好,但现在我已将 C++/CLI 和 C# 项目升级到 .Net 5,这会导致访问冲突:
Exception thrown at 0x00007FFC81A3F528 (clr.dll) in MyApp.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
堆栈跟踪:
mfc140ud.dll!COleControlSite::CreateControlCommon(CWnd * pWndCtrl, const _GUID & clsid, const CControlCreationInfo & creationInfo, const wchar_t * lpszWindowName, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, unsigned int nID, CFile * pPersist, int bStorage, wchar_t * bstrLicKey) Line 224 C++
mfc140ud.dll!COleControlSite::CreateControl(CWnd * pWndCtrl, const CControlCreationInfo & creationInfo, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, unsigned int nID) Line 198 C++
mfc140ud.dll!COleControlContainer::CreateControlCommon(CWnd * pWndCtrl, const _GUID & clsid, const CControlCreationInfo & creationInfo, const wchar_t * lpszWindowName, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, unsigned int nID, CFile * pPersist, int bStorage, wchar_t * bstrLicKey, COleControlSite * * ppNewSite) Line 301 C++
mfc140ud.dll!COleControlContainer::CreateControl(CWnd * pWndCtrl, const CControlCreationInfo & creationInfo, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, unsigned int nID) Line 270 C++
mfc140ud.dll!CWnd::CreateControl(const CControlCreationInfo & creationInfo, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, CWnd * pParentWnd, unsigned int nID) Line 90 C++
[Managed to Native Transition]
CLI.dll!Microsoft::VisualC::MFC::CWinFormsControl<Widget::MyWidget>::InternalCreateManagedControl(CControlCreationInfo& info, unsigned int dwStyle, tagRECT& rect, CWnd* pParentWnd, int nID) Line 122 C++
CLI.dll!Microsoft::VisualC::MFC::CWinFormsControl<Widget::MyWidget>::CreateManagedControl(System::Type^ pType, unsigned int dwStyle, tagRECT& rect, CWnd* pParentWnd, int nID) Line 133 C++
CLI.dll!Microsoft::VisualC::MFC::CWinFormsControl<Widget::MyWidget>::CreateManagedControl(unsigned int dwStyle, tagRECT& rect, CWnd* pParentWnd, int nID) Line 149 C++
CLI.dll!Cli::CreateControl(CWnd* parent, int id) Line 191 C++
其他 C# 功能可以顺利运行,实验性的
gcnew Widget::MyWidget()
也是如此。 我已经尝试项目设置一段时间了,但一无所获。 有什么想法吗?