.NET 相当于 size_t [英] .NET equivalent of size_t

查看:27
本文介绍了.NET 相当于 size_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段 .NET 代码,我想将其移植到 64 位.这些代码基本上是对其他一些 C dll 的一组 P/Invoke 调用.C dll 中的函数之一具有参数size_t".我应该在我的 P/Invoke 签名中使用什么数据类型,以便编组工作正常.我正在考虑使用 IntPtr 或 UIntPtr 但有人说它们是 .NET 中的指针等价物,不应该使用它.有谁知道这个的正确类型是什么?

I have a piece of .NET code which I want to port to 64-bit. The codes basically is a set of P/Invoke calls to some other C dll. One of the functions in the C dll has a parameter 'size_t'. What datatype should I use in my P/Invoke signature so that the marshalling works fine. I was thinking of using a IntPtr or a UIntPtr but some say that they are a pointer equivalent thing in .NET and shouldnt be using it. Does anyone know what the correct type for this is?

推荐答案

UIntPtr 会起作用(IntPtr 可能也会起作用,但 size_t 是无符号的,所以 UIntPtr 更适合)

UIntPtr will work (IntPtr would probably work too, but size_t is unsigned, so UIntPtr is a better fit)

JaredPar 在他的 博客(以及跟进)关于这个.

JaredPar has written something on his blog (and a follow-up) about this.

这篇关于.NET 相当于 size_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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