我可以将IntPtr传递给方法吗? [英] Can I pass an IntPtr to a method ?

查看:94
本文介绍了我可以将IntPtr传递给方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我一直在为较低级别的WinAPI访问控制功能编写一些Pinvoke代码。我有一个指向与TOKEN_ACCESS_INFORMATION中的访问令牌关联的权限的指针,我正在查看权限。我有工作代码但决定将其中的一部分重构为一个泛型方法,该方法给出一个带有count属性的结构的指针,可以检索与该计数相关联的项目数组。问题是传递指针的泛型方法(第一行代码)中的以下代码不会返回一致的结果。从获得指针的方法中,它是预期的。



uint uiPrivilegeCount =(uint)Marshal.PtrToStructure(privilegePointer,typeof(uint) ));



非常感谢



Tony

Hi,

I have been writing some Pinvoke code for lower level WinAPI Access Control functions. I have a pointer to Privileges associated with my access token from the TOKEN_ACCESS_INFORMATION and I am looking at the privileges. I have working code but decided to refactor part of it to a generic method that given a pointer to a structure with a count property could retrieve the array of items associated with the count. The problem is that the following code inside the generic method ( first line of code ) that is passed the pointer does not return a consistent result. From within the method that obtained the pointer it is as expected.

uint uiPrivilegeCount = (uint)Marshal.PtrToStructure(privilegePointer, typeof(uint));

Many thanks

Tony

推荐答案

这篇关于我可以将IntPtr传递给方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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