IntPtr --> HWND 
Author Message
 IntPtr --> HWND

What is the logic of using the IntPtr type to represent
Win32 window handles, as the WinForm Handle property does?

This seems a bit odd to me, why is it a better choice
than Int32? In my C++ interop code I do stuff like:

(HWND)intptr.ToInt32()

To get a HWND; it just seems odd from a C++ point of view
to have an Integer POINTER which doesn't really point to
anything -- I didn't think that HWNDs and HDCs etc. were
*pointers*, just unique int IDs. Am I missing something?

Also, what wizardary is it that prevents the
IntPtr::ToPointer() method being visible in my VB.NET
application's Intellisense, but makes it available to my
C++ application?! :)

Thanks,
dm.



Mon, 20 Jun 2005 23:38:55 GMT  
 IntPtr --> HWND
This is how HWND is defined in win headers:
when STRICT defined:
struct HWND__ { int unused; }; typedef struct HWND__ *HWND;

otherwise:
typedef void *HANDLE;
typedef HANDLE HWND

ToPointer() doesn't work in vb probably because it doesn't support void*?


Quote:
> What is the logic of using the IntPtr type to represent
> Win32 window handles, as the WinForm Handle property does?

> This seems a bit odd to me, why is it a better choice
> than Int32? In my C++ interop code I do stuff like:

> (HWND)intptr.ToInt32()

> To get a HWND; it just seems odd from a C++ point of view
> to have an Integer POINTER which doesn't really point to
> anything -- I didn't think that HWNDs and HDCs etc. were
> *pointers*, just unique int IDs. Am I missing something?

> Also, what wizardary is it that prevents the
> IntPtr::ToPointer() method being visible in my VB.NET
> application's Intellisense, but makes it available to my
> C++ application?! :)

> Thanks,
> dm.



Tue, 21 Jun 2005 00:10:05 GMT  
 IntPtr --> HWND

Quote:
>What is the logic of using the IntPtr type to represent
>Win32 window handles, as the WinForm Handle property does?

>This seems a bit odd to me, why is it a better choice
>than Int32?

For portability reasons. A HWND on Win64 should be 64 bits.

Quote:
>To get a HWND; it just seems odd from a C++ point of view
>to have an Integer POINTER which doesn't really point to
>anything

IntPtr isn't an integer pointer, it's an integer with the size of a
pointer (sizeof(void*)).

Quote:
>I didn't think that HWNDs and HDCs etc. were
>*pointers*, just unique int IDs. Am I missing something?

Well they are. Handles are typically defined as void*.

Quote:
>Also, what wizardary is it that prevents the
>IntPtr::ToPointer() method being visible in my VB.NET
>application's Intellisense, but makes it available to my
>C++ application?! :)

VB.NET doesn't support pointer types.

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.



Tue, 21 Jun 2005 00:11:57 GMT  
 IntPtr --> HWND
Thanks for the input guys.

I guess I bought the hype about VB.NET being a 'first-
class' .NET language a little too readily. I thought that
there were only syntatic language differences between
the .NET languages, not differences in the accesability
of base CLR types.

Thanks,
D.

Quote:
>-----Original Message-----
>What is the logic of using the IntPtr type to represent
>Win32 window handles, as the WinForm Handle property
does?

>This seems a bit odd to me, why is it a better choice
>than Int32? In my C++ interop code I do stuff like:

>(HWND)intptr.ToInt32()

>To get a HWND; it just seems odd from a C++ point of
view
>to have an Integer POINTER which doesn't really point to
>anything -- I didn't think that HWNDs and HDCs etc. were
>*pointers*, just unique int IDs. Am I missing something?

>Also, what wizardary is it that prevents the
>IntPtr::ToPointer() method being visible in my VB.NET
>application's Intellisense, but makes it available to my
>C++ application?! :)

>Thanks,
>dm.
>.



Tue, 21 Jun 2005 00:31:29 GMT  
 IntPtr --> HWND
HWND is a 64-bit value in Win64?


Quote:

> >What is the logic of using the IntPtr type to represent
> >Win32 window handles, as the WinForm Handle property does?

> >This seems a bit odd to me, why is it a better choice
> >than Int32?

> For portability reasons. A HWND on Win64 should be 64 bits.

> >To get a HWND; it just seems odd from a C++ point of view
> >to have an Integer POINTER which doesn't really point to
> >anything

> IntPtr isn't an integer pointer, it's an integer with the size of a
> pointer (sizeof(void*)).

> >I didn't think that HWNDs and HDCs etc. were
> >*pointers*, just unique int IDs. Am I missing something?

> Well they are. Handles are typically defined as void*.

> >Also, what wizardary is it that prevents the
> >IntPtr::ToPointer() method being visible in my VB.NET
> >application's Intellisense, but makes it available to my
> >C++ application?! :)

> VB.NET doesn't support pointer types.

> Mattias

> ===

> http://www.msjogren.net/dotnet/
> Please reply only to the newsgroup.



Tue, 21 Jun 2005 01:49:43 GMT  
 IntPtr --> HWND

Quote:

> >I didn't think that HWNDs and HDCs etc. were
> >*pointers*, just unique int IDs. Am I missing something?

> Well they are. Handles are typically defined as void*.

Yes they are pointers, *but* that doesn't mean you are allowed to
dereference them.  They share representation with pointers, but they
could be offsets into internal tables, or pointers to kernel memory
which you do not have read priviledge on, or keys to a hashtable, or any
number of things.

The important takeaway is that handles are the size of pointers.  They
are not pointers in the sense that it is legal to do pointer-like things
to them.

Ken



Tue, 21 Jun 2005 04:11:26 GMT  
 IntPtr --> HWND
Jill,

Quote:
> HWND is a 64-bit value in Win64?

Yes, alongside HANDLEs and other few types.

--
Tomas Restrepo



Tue, 21 Jun 2005 04:25:11 GMT  
 IntPtr --> HWND

Quote:
> HWND is a 64-bit value in Win64?

No it is a 128-bit value :)
Awake, Win64 is a 64-bit OS. sizeof(void*) returns 8 instead of 4.
Quote:
> Please reply only to the newsgroup.



Tue, 21 Jun 2005 04:44:01 GMT  
 IntPtr --> HWND
Wow.  I would have thought that sizeof(void*) would continue to be 4 and
that they would introduce something like the equivalent of __far to indicate
64-bit pointers.  But, I guess it's too late to change it now. :)



Quote:


> > HWND is a 64-bit value in Win64?
> No it is a 128-bit value :)
> Awake, Win64 is a 64-bit OS. sizeof(void*) returns 8 instead of 4.

> > Please reply only to the newsgroup.



Wed, 22 Jun 2005 13:26:25 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Conversion from System::IntPtr to HWND

2. HWND --> IUnknown

3. HINSTANCE -> HWND (determining when app was closed)

4. HWND -> CWnd

5. Hwnd -> windows object

6. How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()

7. Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)

8. How to get HWND in ::GetDlgItem(HWND hDlg,ID_SECTIONS) before dlg.DoModal()

9. HWND hWnd

10. Question on HWND hDlg Parameter in ::SetDlgItemText(HWND hDlg, int nIDDlgItem, LPTSTR lpString, int nMaxCount)

11. DestroyWindow( HWND hWnd ) doesnt kill window

12. retrieving a HWND hWnd from a UINT wParam

 

 
Powered by phpBB® Forum Software