473,606 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1553
* " active" <ac****@REMOV Ea-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****@REMOV Ea-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.co m> wrote in message
news:OC******** ******@tk2msftn gp13.phx.gbl...
On 2004-01-17, Herfried K. Wagner [MVP] <hi************ ***@gmx.at> wrote:
* " active" <ac****@REMOV Ea-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****@REMOV Ea-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****@REMOV Ea-znet.com> wrote in message
news:O8******** ******@TK2MSFTN GP10.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.co m> wrote in message
news:OC******** ******@tk2msftn gp13.phx.gbl...
On 2004-01-17, Herfried K. Wagner [MVP] <hi************ ***@gmx.at> wrote:
* " active" <ac****@REMOV Ea-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
6042
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 "Handle" is the Win32 handle.
6
3240
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." exception. The problem is that this exception isn't raised somewhere in a method, so it just shows up, and it causes the application to shut down. Is there anyway how to catch this kinds of exceptions? Can I put somewhere a
11
5072
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. Spy++ gives that this window is called _Wwg. How we can get a handle to this window assuming that we do not know beforehand the name of the process,
17
2244
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 "Handle" is the Win32 handle.
2
5724
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 following is a diskette class (vb .net) that works find, in that I can validate a diskette is mounted, dismount it, lock it, unlock it, get diskette geometry, etc., all with a valid handle from CreateFile API! I can even position the file pointer,...
6
2942
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 Application Project. I want to pass Image as one of the parameter but I figure that an Image doesn't have a handle. Previously I had it working in a Web Application Project using the handle of a PictureBox. Is there any workaround? Please help and...
3
4556
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, LVM_GETHEADER,0,0)
2
12634
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 Lib "user32" () As System.IntPtr Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer Private Function...
6
4061
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 I solve this issue. I require this handle in all functions provided by SDK. Thanks
0
7951
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5465
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3930
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2448
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1296
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.