Creating a handle for an object? How?

Discussion in 'C' started by alirezan, May 2, 2011.

  1. alirezan

    alirezan New Member

    Joined:
    May 2, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi guys

    I have these function definitions and I'm supposed to write the functions. I have trouble understanding a part of it. I will explain.
    The create function is supposed to return a handle to a timer. I am not sure how I'm supposed to do that.

    I am planning on creating a class and in the implementation of the create function, I will set a variable to current time (using gettickcount () ) and set the expiry variable to what's passed in. In the isExpired function, I will compare the values against current time (again using gettickcount () ) and determine if timer is expired or not.

    But I don't know how to create a handle for each timer the way the function definitions require me to. Any ideas?

    Thank you
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Not enough info. What OS? Are the timers implemented by the OS or have ou implemented them?

    A handle is just something the computer uses to be able to identify an object. It could be a pointer, or it could just be a number that indexes into a pointer or object table. For example:
    1 "hello"
    2 "world"
    3 "foo"
    4 "bar"

    1-4 could be considered "handles" in this respect. The exact meaning of handle in your situation will depend on the situation, for example if these are Windows handles as implemented by the WinAPI, then the HANDLEs returned by CreateTimer() et al would count as valid handles that could be returned by your functions, unless for any reason you wanted to obfuscate the actual Windows HANDLE values themselves, in which case you'd want to create a lookup table so that your program could deduce the Windows HANDLE from the handle passed in, e.g.
    1 Windows-HANDLE-1
    2 Windows-HANDLE-2
    3 Windows-HANDLE-3

    then your program would get a Windows HANDLE and bung it in this table, return as a handle the lookup value, then on each entry to your library you would take the given handle (1-3) and lookup the actual Windows HANDLE which you would then use to call the Windows function.

    Bit rambly but I hope that's clear ;-)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice