Hans-Gerd Sandhagen
6/27/2007 5:06:00 AM
Gregory Khra schrieb:
> How can I pass a Windows Form handle to unmanaged DLL that expects HWND?
> Even if I have a wrapper calss between managed C# and unmanaged C++, IntPtr
> does not by default cast to HWND. Should I force it? Can somebody give an
> example?
> Gregory
>
Normally that should not be a problem. Example:
C++ DLL:
#include <windows.h>
void NativeFct (HWND hWnd);
C# Wrapper:
class NativeMethods {
[DllImport("my.dll", EntryPoint = "NativeFct")]
public static extern void NativeFct(IntPtr hWnd);
}
C# Form:
class MyForm : Form {
void MyFunc () {
...
NativeMethods(this.Handle);
...
}
}