IntPtr的索引 [英] Indexing of IntPtr
本文介绍了IntPtr的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个指向数组的指针,我想对这个数组应用索引,所以我将
的函数(命名为IntPrt Func [])转到我可以使用的某个成员(如
C ++)Func [5],但是在C#中我收到错误无法使用[]将索引应用于
类型''System.IntPtr'''的表达式。
如何摆脱它?
TNX
-
Tamir Khason
您想要dot.NET吗?只需询问:
"请, www.dotnet.us
I have a pointer to array and I want to apply indexing to this Array so I
have function (name it IntPrt Func[]) to go to certain member I can use (as
C++) Func[5], but in C# I recieve an error "Cannot apply indexing with [] to
an expression of type ''System.IntPtr''".
How to get rid of it?
TNX
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
推荐答案
我认为你误解了IntPtr的本质。它不是用来表示通过interop检索的不透明句柄 - 它不是指向整数或整数大小指针的指针。重点是它的东西。您收到并传递回互操作层(以及操作系统或其他DLL)。如果你想走一个特定的数组,只需将索引放入数组或使用foreach。
你究竟想要实现什么?
问候
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages .csharp /< #G ************** @ TK2MSFTNGP11.phx.gbl>
我有一个指向数组的指针,我想要将索引应用于此数组,以便我将
具有函数(将其命名为IntPrt Func [])转到我可以使用的某个成员(如
C ++)Func [5],但是在C#中我收到一个错误无法使用[]对索引进行索引。
表达式为''System.IntPtr''的表达式。
如何摆脱它?
TNX
-
Tamir Khason
你想要dot.NET吗?只需询问:
"请, www.dotnet.us
---
收到的邮件经过无病毒认证。
由AVG反病毒系统检查( http://www.grisoft.com)。
版本: 6.0.766 /病毒库:513 - 发布日期:17/09/2004
[microsoft.public.dotnet.languages.csharp]
I think you misunderstand the nature of IntPtr. It is mean''t to be used to represent an opaque handle retrieved via interop - its not a pointer to an integer or a pointer of integer size. The point is its a "thing" that you receive from and pass back to the interop layer (and so to the operating system or some other DLL). if you want to walk a specific array just index into the array or use foreach.
What exactly are you trying to achieve?
Regards
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#G**************@TK2MSFTNGP11.phx.gbl>
I have a pointer to array and I want to apply indexing to this Array so I
have function (name it IntPrt Func[]) to go to certain member I can use (as
C++) Func[5], but in C# I recieve an error "Cannot apply indexing with [] to
an expression of type ''System.IntPtr''".
How to get rid of it?
TNX
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
[microsoft.public.dotnet.languages.csharp]
正如我之前提到的,我构建了一个函数,从非托管返回
指向数组项的指针覆盖了this。方法,所以当使用Func [1]它
将返回指向源数组的第一个成员的指针,但是(请参阅消息)调用此函数时出现
错误>
" Richard Blewett [DevelopMentor]" < RI ****** @ develop.com>在留言中写道
新闻:OX ************** @ tk2msftngp13.phx.gbl ...
As I mentioned earlier I build a function with return from unmanaged the
pointer to array item on override of "this" method so when using Func[1] it
will return the pointer to 1st member of source array, but (see message) an
error on calling this function
"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message
news:OX**************@tk2msftngp13.phx.gbl...
我觉得你误会了IntPtr的本质。它不是用来代表通过互操作检索的不透明句柄 - 它不是指向整数或整数大小指针的指针。重点是它的东西。您收到并传递回互操作层(以及操作系统或其他DLL)。如果你想走一个特定的数组只需索引
到数组中或使用foreach。
你到底想要实现什么?
问候
Richard Blewett - DevelopMentor
http:// staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/< #G ***** *********@TK2MSFTNGP11.phx.gbl>
我有一个指向数组的指针,我想对这个数组应用索引,所以我有功能(命名它) IntPrt Func [])去某些成员我可以使用
(作为
C ++)Func [5],但在C#中我收到错误无法用[]
应用索引
System.IntPtr类型的表达式。
如何摆脱它?
TNX
-
Tamir Khason
你想要dot.NET吗?只需询问:
请, www.dotnet.us "
---
收到的邮件经过无病毒认证。
由AVG反病毒系统检查( http://www.grisoft.com)。
版本:6.0.766 /病毒库:513 - 发布日期:17/09/2004
[microsoft.public.dotnet.languages.csharp]
I think you misunderstand the nature of IntPtr. It is mean''t to be used to
represent an opaque handle retrieved via interop - its not a pointer to an
integer or a pointer of integer size. The point is its a "thing" that you
receive from and pass back to the interop layer (and so to the operating
system or some other DLL). if you want to walk a specific array just index
into the array or use foreach.
What exactly are you trying to achieve?
Regards
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#G**************@TK2MSFTNGP11.phx.gbl>
I have a pointer to array and I want to apply indexing to this Array so I
have function (name it IntPrt Func[]) to go to certain member I can use
(as
C++) Func[5], but in C# I recieve an error "Cannot apply indexing with []
to
an expression of type ''System.IntPtr''".
How to get rid of it?
TNX
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
[microsoft.public.dotnet.languages.csharp]
我是否做到了:你把数组转换为IntPtr,并且想要稍后使用那个
IntPtr来访问数组中的数据?这将永远不会起作用:GC可能会移动数组,甚至可以在不更改IntPtr的情况下释放它。你可以暂时修复mamanged堆上的一个对象,但这只能在一个固定块内部实现
,一旦你离开一个函数就会结束。
Niki
" Tamir Khason" < TA ********** @ tcon-NOSPAM.co.il>写在
新闻:ep ************* @tk2msftngp13.phx.gbl ...
Did I get that right: You cast an array to IntPtr, and want to use that
IntPtr later to access data in the array? This will never work: The GC might
move the array, or even free it without changing your IntPtr. You can
temporarily fix an object on the mamanged heap, but this is only possible
inside a fixed-block, which ends as soon as you leave a function.
Niki
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in
news:ep*************@tk2msftngp13.phx.gbl...
正如我之前提到的,我建立了一个函数从非托管返回
指向覆盖this的数组项。方法所以当使用Func [1]
它会将指针返回到源数组的第一个成员,但是(参见
消息)调用此函数时出错
理查德Blewett [DevelopMentor]" < RI ****** @ develop.com>在消息中写道
新闻:OX ************** @ tk2msftngp13.phx.gbl ...
As I mentioned earlier I build a function with return from unmanaged the
pointer to array item on override of "this" method so when using Func[1]
it will return the pointer to 1st member of source array, but (see
message) an error on calling this function
"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message
news:OX**************@tk2msftngp13.phx.gbl...
我认为你误解了IntPtr的本质。它不是用来代表通过互操作检索的不透明句柄 - 它不是指向整数或整数大小指针的指针。重点是它的东西。您收到并传递回互操作层(以及操作系统或其他DLL)。如果你想走一个特定的数组只需索引
到数组中或使用foreach。
你到底想要实现什么?
问候
Richard Blewett - DevelopMentor
http:// staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/< #G ***** *********@TK2MSFTNGP11.phx.gbl>
我有一个指向数组的指针,我想对这个数组应用索引,所以我有功能(命名它) IntPrt Func [])去某些成员我可以使用
(作为
C ++)Func [5],但在C#中我收到错误无法用[]
应用索引
System.IntPtr类型的表达式。
如何摆脱它?
TNX
-
Tamir Khason
你想要dot.NET吗?只需询问:
请, www.dotnet.us "
---
收到的邮件经过无病毒认证。
由AVG反病毒系统检查( http://www.grisoft.com)。
版本:6.0.766 /病毒库:513 - 发布日期:17/09/2004
[microsoft.public.dotnet.languages.csharp]
I think you misunderstand the nature of IntPtr. It is mean''t to be used to
represent an opaque handle retrieved via interop - its not a pointer to an
integer or a pointer of integer size. The point is its a "thing" that you
receive from and pass back to the interop layer (and so to the operating
system or some other DLL). if you want to walk a specific array just index
into the array or use foreach.
What exactly are you trying to achieve?
Regards
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#G**************@TK2MSFTNGP11.phx.gbl>
I have a pointer to array and I want to apply indexing to this Array so I
have function (name it IntPrt Func[]) to go to certain member I can use
(as
C++) Func[5], but in C# I recieve an error "Cannot apply indexing with []
to
an expression of type ''System.IntPtr''".
How to get rid of it?
TNX
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
[microsoft.public.dotnet.languages.csharp]
这篇关于IntPtr的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文