【问题标题】:C++/CLI with C# WPF passing HWND and HINSTANCEC++/CLI 与 C# WPF 传递 HWND 和 HINSTANCE
【发布时间】:2013-06-25 14:48:13
【问题描述】:

如何传递 C# WPF 表单的 HWND 和 HINSTANCE?

尝试:

C++/CLI:

BOOL Initialize(double width, double height, HWND parent, HINSTANCE hiparent)
{

C#

HwndSource hwnd = (HwndSource)HwndSource.FromVisual(this.renderControl);
IntPtr hinstance = Marshal.GetHINSTANCE(typeof(App).Module);

engine.Initialize(this.Width, this.Height, hwnd, hinstance);

但是抛出:

参数 4:无法从 'System.IntPtr' 转换为 'HINSTANCE__*' 参数 3:无法从 'System.Windows.Interop.HwndSource' 转换为 'HWND__*'

那么我怎样才能将这些转换成那些呢?

【问题讨论】:

    标签: c# wpf c++-cli


    【解决方案1】:

    考虑试试这个:

    engine.Initialize(this.Width, this.Height, hwnd.Handle.ToPointer(), hinstance.ToPointer());
    

    IntPtr.ToPointer() 返回一个void*,它应该可以转换为HWNDHINSTANCE

    【讨论】:

      【解决方案2】:

      尝试类似:

      engine.Initialize(this.Width, this.Height, (HWND)(hwnd.Handle.ToPointer()), (HINSTANCE)hinstance.ToPointer());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-28
        • 1970-01-01
        • 1970-01-01
        • 2020-04-10
        • 1970-01-01
        • 1970-01-01
        • 2011-09-15
        • 2016-09-20
        相关资源
        最近更新 更多