none
What is HANDLE In C programming?

    Question

  • Hi All,

    What is HANDLE in C programming? What will be the equivalent implementation in C#.

    Thanx  in Advance,
    Bibek
    Thursday, May 08, 2008 8:35 AM

Answers

  • Is sort of like a reference. Usually an integer or pointer value that refers to some object, but you as the consumer shouldn't care about the actual handle value. You just use it to identify the object.

     

    IntPtr is usually a good type to represent raw handles in managed code. But you also have the HandleRef and SafeHandle classes that add some additional functionality.

     

    Thursday, May 08, 2008 11:19 AM
  • It's a simple number that Windows gives you back when you allocate an operating system resource.  A file, socket, bitmap, etc.  There's a ton of them.  That number is a 32-bit value, 64-bits on a 64-bit operating system.  You store them in an IntPtr in C#.

    Most methods that deal with handles are in the Marshal class.  The .NET framework does its best to hide them from you by wrapping them in a class.  FileStream, Socket, Bitmap, etc.  If a class has a Dispose() method, there's likely to be a handle stored in a private member.
    Thursday, May 08, 2008 11:22 AM
    Moderator

All replies

  • Is sort of like a reference. Usually an integer or pointer value that refers to some object, but you as the consumer shouldn't care about the actual handle value. You just use it to identify the object.

     

    IntPtr is usually a good type to represent raw handles in managed code. But you also have the HandleRef and SafeHandle classes that add some additional functionality.

     

    Thursday, May 08, 2008 11:19 AM
  • It's a simple number that Windows gives you back when you allocate an operating system resource.  A file, socket, bitmap, etc.  There's a ton of them.  That number is a 32-bit value, 64-bits on a 64-bit operating system.  You store them in an IntPtr in C#.

    Most methods that deal with handles are in the Marshal class.  The .NET framework does its best to hide them from you by wrapping them in a class.  FileStream, Socket, Bitmap, etc.  If a class has a Dispose() method, there's likely to be a handle stored in a private member.
    Thursday, May 08, 2008 11:22 AM
    Moderator