473,395 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Handle should be Integer or IntPtr?

I downloaded the Win32 Library which saved me MUCH work.

Some (All?) of the returned handles are typed int.

As I used them I often changed them in my copy of win32 to IntPtr because an
argument that used it was typed IntPtr.

Now I wonder if a Handle make more sense being an integer or an IntPtr.

I believe it's really an index rather than a pointer so Integer seems to
make more sense.
Any helpful comments would be appreciated,
Cal
Nov 20 '05 #1
6 1541
* " active" <ac****@REMOVEa-znet.com> scripsit:
I downloaded the Win32 Library which saved me MUCH work.

Some (All?) of the returned handles are typed int.

As I used them I often changed them in my copy of win32 to IntPtr because an
argument that used it was typed IntPtr.

Now I wonder if a Handle make more sense being an integer or an IntPtr.
I prefer 'IntPtr', but it will work with 'Int32' (a/k/a 'Integer') too.
I believe it's really an index rather than a pointer so Integer seems to
make more sense.


It's an identification number.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
On 2004-01-17, Herfried K. Wagner [MVP] <hi***************@gmx.at> wrote:
* " active" <ac****@REMOVEa-znet.com> scripsit:
I downloaded the Win32 Library which saved me MUCH work.

Some (All?) of the returned handles are typed int.

As I used them I often changed them in my copy of win32 to IntPtr because an
argument that used it was typed IntPtr.

Now I wonder if a Handle make more sense being an integer or an IntPtr.


I prefer 'IntPtr', but it will work with 'Int32' (a/k/a 'Integer') too.
I believe it's really an index rather than a pointer so Integer seems to
make more sense.


It's an identification number.


IntPtr... For one important reason - Win64. int maps to System.Int32,
System.IntPtr will take on the default size for the system - 64-bits on
a 64-bit system.

--
Tom Shelton [MVP]
Nov 20 '05 #3
Now I wonder if a Handle make more sense being an integer or an IntPtr.


Preferrably they should be a System.Runtime.InteropServices.HandleRef,
or IntPtr where that doesn't work.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #4
Thanks for the two replies. That's what I'll do.

I also just noticed that DotNet used IntPtr for the handles I checked.

Isn't that a strong reason for using IntPtr - or is it not?
Thanks again,
Cal
"Tom Shelton" <to*@mtogden.com> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
On 2004-01-17, Herfried K. Wagner [MVP] <hi***************@gmx.at> wrote:
* " active" <ac****@REMOVEa-znet.com> scripsit:
I downloaded the Win32 Library which saved me MUCH work.

Some (All?) of the returned handles are typed int.

As I used them I often changed them in my copy of win32 to IntPtr because an argument that used it was typed IntPtr.

Now I wonder if a Handle make more sense being an integer or an IntPtr.


I prefer 'IntPtr', but it will work with 'Int32' (a/k/a 'Integer') too.
I believe it's really an index rather than a pointer so Integer seems to make more sense.


It's an identification number.


IntPtr... For one important reason - Win64. int maps to System.Int32,
System.IntPtr will take on the default size for the system - 64-bits on
a 64-bit system.

--
Tom Shelton [MVP]

Nov 20 '05 #5
* " active" <ac****@REMOVEa-znet.com> scripsit:
Thanks for the two replies. That's what I'll do.

I also just noticed that DotNet used IntPtr for the handles I checked.

Isn't that a strong reason for using IntPtr - or is it not?


As Tom said, it will make transition to 64 bit easier because 'IntPtr'
will be 64 bit on 64 bit systems. The 'Handle' property, for example,
is an 'IntPtr' too, that's why I prefer 'IntPtr' for handles.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Cal,
As Tom & Herfried pointed out, its better to use IntPtr as a Handle, as a
Handle is an "opaque" type (it may be a pointer, it may be an index, it may
be a magic cookie) it is really API specific on what the handle actually
represents. Its opaque in that it does not matter what it represents.

I understand that the framework using IntPtr for the reasons that Tom &
Herfried cited.

As the IntPtr help topic itself states "A platform-specific type that is
used to represent a pointer or a handle"
http://msdn.microsoft.com/library/de...ClassTopic.asp

Hope this helps
Jay

" active" <ac****@REMOVEa-znet.com> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
Thanks for the two replies. That's what I'll do.

I also just noticed that DotNet used IntPtr for the handles I checked.

Isn't that a strong reason for using IntPtr - or is it not?
Thanks again,
Cal
"Tom Shelton" <to*@mtogden.com> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
On 2004-01-17, Herfried K. Wagner [MVP] <hi***************@gmx.at> wrote:
* " active" <ac****@REMOVEa-znet.com> scripsit:
> I downloaded the Win32 Library which saved me MUCH work.
>
> Some (All?) of the returned handles are typed int.
>
> As I used them I often changed them in my copy of win32 to IntPtr because an> argument that used it was typed IntPtr.
>
> Now I wonder if a Handle make more sense being an integer or an IntPtr.
I prefer 'IntPtr', but it will work with 'Int32' (a/k/a 'Integer') too.
> I believe it's really an index rather than a pointer so Integer seems to> make more sense.

It's an identification number.


IntPtr... For one important reason - Win64. int maps to System.Int32,
System.IntPtr will take on the default size for the system - 64-bits on
a 64-bit system.

--
Tom Shelton [MVP]


Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fred Hebert | last post by:
I am trying to use a 3rd party DLL that requires the main window handle as a parameter. e.g. MyFunc(WHND MyHandle); The example looks something like this: Result = MyFunc(Handle); Where...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
11
by: objectref | last post by:
Hi to all, is there a way to get the window handle of the main window of an application or process ? For example, if someone opens Microsoft Word, he gets a window so he/she can write text....
17
by: Fred Hebert | last post by:
I am trying to use a 3rd party DLL that requires the main window handle as a parameter. e.g. MyFunc(WHND MyHandle); The example looks something like this: Result = MyFunc(Handle); Where...
2
by: Schorschi | last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle error? =========================================================================== Ok, the visual basic gurus, help! The...
6
by: anonymous | last post by:
hi all, I'm trying to use the capCreateCaptureWindow (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_capcreatecapturewindow.asp) in a Windows...
3
by: Simon Abolnar | last post by:
I am using VB.NET 2003 Framework 1.1 How can I get ListView header handle. I tried in this way: Dim headerHandle As IntPtr HeaderHandle=SendMessage(listView.Handle.ToInt32,...
2
by: David A. Osborn | last post by:
I'm having problems getting the caption on the active window handle. The active window handle seems to always come back as zero and the caption blank. Private Declare Function GetActiveWindow...
6
by: erupakat | last post by:
Hello, I am using VS2005 along with a third part SDK . In that I am having a function called OpenInterface() which will return a Handle .I think in VS2005 they replaced Handle with IntPtr. How can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.