Miguel Petersen
Miguel Petersen

Reputation: 65

C++/CLI with C# WPF passing HWND and HINSTANCE

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

Answers (2)

Pragmateek
Pragmateek

Reputation: 13374

Try something like:

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

Upvotes: 1

user203570
user203570

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

Related Questions