Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
I am trying to create an IntPtr like this:

VB
Dim pid As New IntPtr(Int64.MaxValue)


The C# equivalent would be something like:

C#
IntPtr pid = new IntPtr(Int64.MaxValue);



I keep getting the error "OverflowException".
How can I make this work?

edit:
This is being compiled with "AnyCPU". It's a device application using .NET CF 2.0; The target device is running Windows Mobile 6.5
Posted
Updated 1-Jan-14 23:18pm
v2

Hi try this..


C#
IntPtr pid = new IntPtr(int.MaxValue);


The IntPtr type is designed to be an integer whose size is platform-specific. That is, an instance of this type is expected to be 32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit hardware and operating systems.

hope your machine is 32 bit operating system.

reference: intptr[^]
 
Share this answer
 
In the Object Browser of Visual Studio, when you go to IntPtr(long), then you see the following under Exceptions

Object Browser
System.OverflowException: On a 32-bit platform, value is too large or too small to represent as an System.IntPtr.


I guess you are running your application on a 32-bit platform, so you get this error.
 
Share this answer
 
Comments
seph0r 2-Jan-14 5:54am    
Indeed, its an 32bit device, that caused the error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900