CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    Exclamation What is a HANDLE?

    I have something which is not quite sure about it... it is HANDLE .. I though it was a kind of data type.. But I heard from my friend saying that : it was a thread .. Is it true..?

    THank YOu @!

  2. #2
    Join Date
    Mar 2004
    Posts
    235
    A handle is ... Well its pretty hard to explain. You can have a handle to a thread and a handle to device context. You can also have a handle to a file. You can think of it as a pointer to a structure that windows hides from you to keep it more user friendly for the programmer . To close any HANDLE use CloseHandle() api. The usefull ness of this is you can have an array of handles for various things e.g. files, threads, processes etc... and have a simple loop closeing all the handles using CloseHandle().

    Hope this helps

  3. #3
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108
    So.. what I heard from friend is... I think is partial true (I mean handle to thread)... basically it just a structure.. right?

    THanks a lot..

  4. #4
    Join Date
    May 2000
    Location
    Indore (MP) INDIA.
    Posts
    356
    Although answer has explained the stuff. Yes, a HANDLE is a pointer to Internal Data structure that is explaining may be a Thread, an Event, a File etc. When the Handle is passed to CloseHandle() API, it correctly understand what it is representing and thus Cleans-Up in appropriate way.

    For your interest, here is the code snippet from WinNt.H :
    Code:
    #ifdef STRICT
    typedef void *HANDLE;
    #else
    typedef PVOID HANDLE;
    #endif
    typedef HANDLE *PHANDLE;
    Regards.

    -Vipul Pathak ;

  5. #5
    Join Date
    Jan 2004
    Posts
    56
    Basically HANDLE is a UINT value, sometime it's a pointer, sometime it's a index... More detail, u have to know what object is. Maybe an article in MSDN - 'Give me a handle, I'll show you an object' - will help u a little bit.
    Last edited by sephiroth2m; June 1st, 2004 at 03:23 AM.
    Trust urself!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured