473,373 Members | 1,707 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,373 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 1540
* " 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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.