0

如何传递 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__*'

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

4

2 回答 2

3

考虑试试这个:

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

IntPtr.ToPointer()返回 avoid*应该可以转换为HWNDand HINSTANCE

于 2013-06-25T14:55:44.110 回答
1

尝试类似:

engine.Initialize(this.Width, this.Height, (HWND)(hwnd.Handle.ToPointer()), (HINSTANCE)hinstance.ToPointer());
于 2013-06-25T14:55:50.227 回答