如何使用Int64创建IntPtr?

编程入门 行业动态 更新时间:2024-10-20 00:42:19
本文介绍了如何使用Int64创建IntPtr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

Dim pid 作为 新 IntPtr ( 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?

本文发布于:2023-11-12 12:10:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581465.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   IntPtr

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!