2013-06-25 92 views
0

如何传递C#WPF表单的HWND和HINSTANCE?C++ WPF通过HWND和HINSTANCE的C++/CLI

尝试:

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:can不能转换从“System.Windows.Interop.HwndSource”到 “HWND __ *”

所以,我怎么能转换到这些的?

回答

2

考虑尝试这样的:

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

IntPtr.ToPointer()返回void*这应该是转换为HWNDHINSTANCE

+0

完美同步,+1;) – Pragmateek

1

尝试类似:

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