如何传递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 __ *'
那么如何将这些转化为那些?
答案 0 :(得分:2)
考虑尝试这个:
engine.Initialize(this.Width, this.Height, hwnd.Handle.ToPointer(), hinstance.ToPointer());
IntPtr.ToPointer()
返回void*
,该HWND
应该可转换为HINSTANCE
和{{1}}。
答案 1 :(得分:1)
尝试类似:
engine.Initialize(this.Width, this.Height, (HWND)(hwnd.Handle.ToPointer()), (HINSTANCE)hinstance.ToPointer());