Thread: windows.h handles in c

  1. #1
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121

    windows.h handles in c

    Hey there...
    I have been searching google.com for quite a while and I haven't been able to find a good tutorial on c handles. Can anyone give me a good site to go to or maybe a book to get a hold of.

    Thank you!
    -- Will you show me how to c++?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Are you asking about the HANDLE data type or on Windows programming in general?

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In general, a HANDLE is some sort of identifier that, to you, is just something you have to pass back to identify some resource/object (a window, a file, a thread, a process, a mouse cursor image, a drawing pen, etc, etc). As you would have on a physical object, say a saw, hammer, suitcase or oscilloscope: a handle to hold it when using/moving the object.

    How a handle is implemented depends on the architecture of the OS. The handle can be an index into an array of objects of that type, a pointer or a composite type (e.g. some sort of index combined with for example a "magic" number to identify which type of object). To you, it should not matter, since you can't do anything with a handle other than pass it to a function that accepts that sort of handle.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    The HANDLE data type... im sorry for not being clear enough before. I have found alot of articles on windows programming in general but not the HANDLE data type. I know how to use them in a very basic manor. I want more control etc. Thnk you mats i know what they are and your explenation actually gave me a better idea. But i need a book or something. Im sure there ahs to be something out there. Thank you!!

    -mramazing
    -- Will you show me how to c++?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Maybe you can explain in more detail what you actually would like to do with a handle (and what type of handle it is, that is, what type of object have you created).

    In general, windows returns a pointer to some internal data structure when it gives you a handle. All handles have the same (but unknown to me) base data, but different data type added "after" the base. Essentially this implements a simple version of derived classes in C++.

    But essentially, you can't "do" anything with these handles - as far as I know, it could even be a kernel only memory address that you get back, so it may not even be user-mode writable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Quote Originally Posted by matsp View Post
    All handles have the same (but unknown to me) base data
    Actually, HANDLE is a synonym for PVOID, which is a synonym to void *.

    Windows Data Types

    Of course, in the case of HANDLE, it's not really important to know this.
    I hate real numbers.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Yes, but just the fact it's a void * doesn't really tell you anything about what it really points to, which I think was the point of matsp's description of abstraction of the type.

  8. #8
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    well i would like to know how to control external applications from mine. So that i can do scripting like tasks in c or c++.
    -- Will you show me how to c++?

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mramazing View Post
    well i would like to know how to control external applications from mine. So that i can do scripting like tasks in c or c++.
    There are process control functions in Windows, and that is what you need to use to create, destroy and otherwise control processes from a Windows process.

    See: http://msdn.microsoft.com/en-us/libr...47(VS.85).aspx

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    C was not written for scripts. That's what console scripting was all about.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems reading windows.h
    By yaya in forum Windows Programming
    Replies: 7
    Last Post: 05-22-2009, 02:33 PM
  2. Problem with DB handles
    By pokks in forum C Programming
    Replies: 4
    Last Post: 01-04-2006, 12:06 PM
  3. organizing window handles
    By FOOTOO in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 11:53 PM
  4. Handles to visible programs
    By Snip in forum Windows Programming
    Replies: 3
    Last Post: 03-26-2005, 08:52 PM
  5. UNICODE and windows.h help
    By nextus in forum Windows Programming
    Replies: 3
    Last Post: 03-02-2003, 03:13 PM