[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

how to pass Form handle to unmanaged code

Gregory Khra

6/26/2007 10:22:00 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

5 Answers

Hans-Gerd Sandhagen

6/27/2007 5:06:00 AM

0

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);
...
}
}

Gregory Khra

6/27/2007 4:24:00 PM

0

"Hans-Gerd Sandhagen" wrote:
> 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

(Mattias Sjögren)

6/27/2007 6:46:00 PM

0

>I am getting a compiler error: cannot convert parameter ... from
>'System::IntPtr' to 'HWND'. This error was the reason for my post.

Then I guess you're using C++ even though your original post said C#.

In C++ you want to call IntPtr::ToPointer and then cast the returned
void* to HWND.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.n... | http://www.dotneti...
Please reply only to the newsgroup.

Rugby

7/1/2010 7:56:00 PM

0

On Jul 1, 2:14 pm, "Matthew B. Tepper" <oy @earthlink.net> wrote:

> Actually I like Horowitz' "Vers la flamme" because it's fun ... to watch.
>
> --


Here is his, with the score to follow, also fun:
http://www.youtube.com/watch?v=WlqGkVc29Gw&fe...

Rugby

Rugby

7/1/2010 8:08:00 PM

0

On Jul 1, 2:56 pm, Rugby <steveha...@gmail.com> wrote:


And Koji Attwood plays Scriabin Sonata # 10 :
http://www.youtube.com/watch?v=GPFvgSMS4bM&feature=PlayList&p=606E2930CBC406FE&playnext_from=PL&playnext=1&a...

Rugby