HighTechTalks DotNet Forums  

how to pass Form handle to unmanaged code

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss how to pass Form handle to unmanaged code in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
=?Utf-8?B?R3JlZ29yeSBLaHJh?=
 
Posts: n/a

Default how to pass Form handle to unmanaged code - 06-26-2007 , 06:22 PM






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


Reply With Quote
  #2  
Old   
Hans-Gerd Sandhagen
 
Posts: n/a

Default Re: how to pass Form handle to unmanaged code - 06-27-2007 , 01:06 AM






Gregory Khra schrieb:
Quote:
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);
...
}
}


Reply With Quote
  #3  
Old   
=?Utf-8?B?R3JlZ29yeSBLaHJh?=
 
Posts: n/a

Default Re: how to pass Form handle to unmanaged code - 06-27-2007 , 12:24 PM



"Hans-Gerd Sandhagen" wrote:
Quote:
Normally that should not be a problem.
I am getting a compiler error: cannot convert parameter ... from
'System::IntPtr' to 'HWND'. This error was the reason for my post.
Gregory


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.