Reputation: 65
How can I pass the HWND and HINSTANCE of a C# WPF Form?
Attempt:
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);
But throws:
Argument 4: cannot convert from 'System.IntPtr' to 'HINSTANCE__*' Argument 3: cannot convert from 'System.Windows.Interop.HwndSource' to 'HWND__*'
So how can I convert these into those?
Upvotes: 0
Views: 2832
Reputation: 13374
Try something like:
engine.Initialize(this.Width, this.Height, (HWND)(hwnd.Handle.ToPointer()), (HINSTANCE)hinstance.ToPointer());
Upvotes: 1
Reputation:
Consider trying this:
engine.Initialize(this.Width, this.Height, hwnd.Handle.ToPointer(), hinstance.ToPointer());
IntPtr.ToPointer()
returns a void*
which should be convertible to HWND
and HINSTANCE
.
Upvotes: 3