如何使用Int64创建IntPtr? [英] How can I create an IntPtr with an Int64?

查看:85
本文介绍了如何使用Int64创建IntPtr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建这样的IntPtr:



  Dim  pid 作为   IntPtr (< span class =code-sdkkeyword> Int64  .MaxValue)





等效的C#类似于:



  IntPtr  pid =  new   IntPtr  Int64  .MaxValue); 







我一直收到错误OverflowException。

我怎样才能做到这一点?



编辑:

这是用AnyCPU编译的。它是使用.NET CF 2.0的设备应用程序;目标设备正在运行Windows Mobile 6.5

解决方案

您好b $ b试试这个..





  IntPtr  pid =  new   IntPtr  int  .MaxValue); 





IntPtr类型设计为整数,其大小为特定于平台。也就是说,这种类型的实例预计在32位硬件和操作系统上 32位,并且64位上的 64位位硬件和操作系统



希望您的机器是32位操作系统。



参考: intptr [ ^ ]


在Visual Studio的对象浏览器中,当你转到 IntPtr(long),然后你会看到以下例外



对象浏览器

System.OverflowException:在32位平台上,值太大或太小而无法表示为System.IntPtr。





我猜你是在32位平台上运行你的应用程序,所以你得到这个错误。

I am trying to create an IntPtr like this:

Dim pid As New IntPtr(Int64.MaxValue)



The C# equivalent would be something like:

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

解决方案

Hi try this..


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[^]


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.


这篇关于如何使用Int64创建IntPtr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆