Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
互操作C++/C#0x0000071 我想从C++程序中调用WPF GUI。GUI可以正常打开,但当我关闭它时,出现以下错误: Exception thrown at 0x74ae3e28 in NewRibbon.exe: 0x0000071A: The remote procedure call was canceled, or if a call time-out was specified, the call timed out._C#_C++_Wpf - Fatal编程技术网

互操作C++/C#0x0000071 我想从C++程序中调用WPF GUI。GUI可以正常打开,但当我关闭它时,出现以下错误: Exception thrown at 0x74ae3e28 in NewRibbon.exe: 0x0000071A: The remote procedure call was canceled, or if a call time-out was specified, the call timed out.

互操作C++/C#0x0000071 我想从C++程序中调用WPF GUI。GUI可以正常打开,但当我关闭它时,出现以下错误: Exception thrown at 0x74ae3e28 in NewRibbon.exe: 0x0000071A: The remote procedure call was canceled, or if a call time-out was specified, the call timed out.,c#,c++,wpf,C#,C++,Wpf,为此,我开发了以下代码: C#接口 namespace WpfForm { [ComVisible(true)] [Guid("38BA38B5-99AA-4564-B1D5-B117CFFF46DB")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IWindows { [DispId(1)] void openWindo

为此,我开发了以下代码:

  • C#接口

    namespace WpfForm
    {
        [ComVisible(true)]
        [Guid("38BA38B5-99AA-4564-B1D5-B117CFFF46DB")]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        public interface IWindows
        {
            [DispId(1)]
            void openWindow();        
    
            [DispId(2)]
            void close();
        }
    }
    
    namespace WpfForm
    {
        [Guid("3C324C9B-E5F2-430C-B591-CB9CAF84B2A4")]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        public interface IWindowsEvents
        {
        }
    }
    
  • C#实施

    namespace WpfForm
    {
        [ComVisible(true)]
        [Guid("F53AD10C-CBD4-4E8D-9782-3395E051F414")]
        [ClassInterface(ClassInterfaceType.None)]
        [ComSourceInterfaces(typeof(IWindowsEvents))]
        [ProgId("WpfForm.ManagedWindows")]
        public class ManagedWindows : IWindows
        {
            private WpfForm.MainWindow m_form;
            private WindowInteropHelper wnd;
    
            [ComVisible(true)]
            public void openWindow()
            {
                try
                {
                    m_form = new WpfForm.MainWindow();
                    m_form.Closing += M_form_Closing;
                    m_form.Closed += M_form_Closed;
                    m_form.ShowInTaskbar = false;
    
                    m_form.ShowDialog();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("EXCEPTION: " + ex.Message);
                }
            }
    
            [ComVisible(true)]
            public void close()
            {
                m_form.Close();
                m_form = null;
            }
        }
    }
    
<>我用C++代码打开C++的WPF表单:

HRESULT tmp = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

IWindowsPtr pWindows;
pWindows.CreateInstance(__uuidof(ManagedWindows));

try
{
    pWindows->openWindow();
}
catch (_com_error& ce)
{
    AfxMessageBox((LPCTSTR)ce.ErrorMessage());
}

if ((tmp == S_OK) || (tmp == S_FALSE))
    CoUninitialize();
我如何解决它

我已经搜索了前面的问题,但还没有找到解决问题的方法

关于,

路易吉