Using IntPtr with IComparer

2019-08-28 01:17发布

Three related questions here:

  • The IntPtr structure apparently does not implement < and > operators. Is there a way to perform this comparison without converting the structure to an int or long?
  • Why are the < and > operators not implemented on this structure?
  • I am enumerating windows from a 32 bit process. Windows from 64 bit processes also seem to be included, which is fine. How can I tell whether to use ToInt32 or ToInt64 on the IntPtr structure?

Context: Windows 7 (64 bit), VS 2010, WinForms (32 bit).

The target windows I want to extract include 64 bit apps such as the Windows Sidebar containing gadgets. If I have taken any wrong assumptions, please let me know.

1条回答
别忘想泡老子
2楼-- · 2019-08-28 02:01

Why are the < and > operators not implemented on this structure?

Because there is no point (in most cases) of comparing if address of a pointer is less or bigger of some other number or other address. By the way IntPtr class provides equality function too.

IntPtr.Equals

查看更多
登录 后发表回答