Search code examples
c#intptr

How to declare a IntPtr?


I have a Window handle Picker and it says my handle is 0094167C. When I declare the variable in c# the letter in this code gives an error. How to declare?

public const IntPtr WinHandle = 0094167C;


Solution

  • You know that the handle will typically change with each application and/or system start? This means your constant is subject to failure anyway.

    If, however, you really want to assign a constant other than zero to an IntPtr (which would be IntPtr.Zero), the documentation states that there are constructors that take Int32, Int64 or Void* as parameter.