CreateWaitableTimer()

This is a discussion on CreateWaitableTimer() within the Windows Programming forums, part of the Platform Specific Boards category; Hi there, I'm working on something where I need to create a waitable timer event to be used in conjunction ...

  1. #1
    Registered User NewtonApple's Avatar
    Join Date
    Aug 2001
    Posts
    11

    Question CreateWaitableTimer()

    Hi there, I'm working on something where I need to create a waitable timer event to be used in conjunction of winsock overlapped i/o. for some reason when i tried to set it up using CreateWaitableTimer() in VC++ (6.0), it complained that there's no such function: "error C2065: 'CreateWaitableTimer' : undeclared identifier." The code i use is as follow:

    Code:
     Handel waitEvents = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
    I even tried to compile the code from (here for link )MSDN and it still won't work... if someone knows the reason why this is so please let me know. Thanks in advance..
    Last edited by NewtonApple; 02-22-2003 at 02:22 AM.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Are you using an NT cored system or 9x? Waitable timers are 32 bit specific.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072

    Both NT and 9x are 32-bit operating systems.

    CreateWaitableTimer is included in Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, and Windows 98.

    You'll need to download a new SDK, or load the function dynamically from kernel32.dll using GetProcAddress(). I recommend downloading a new SDK.
    http://www.microsoft.com/msdownload/...sdk/sdkupdate/
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    By 32 bit I mean genuine 32 bit, not a 16/32 bit lash up such as the 9x core. From MSDN...

    >>>
    Windows NT: Requires version 4.0 or later.
    Windows: Unsupported.
    Windows CE: Unsupported.
    Header: Declared in winbase.h.
    Import Library: Use kernel32.lib.
    Unicode: Implemented as Unicode and ANSI versions on Windows NT.
    <<<

    ... from the CreateWaitableTimer() entry. That may have changed of course, but that is what mine says, and by the looks of the error message he is getting, that would seem to be his problem.

    *** EDIT ***

    The CreateWaitableTimer() documentation at the web site does, indeed, show that it can be retro fitted - my MSDN disks are out of date. However, I would still suspect that this is what his problem is.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User NewtonApple's Avatar
    Join Date
    Aug 2001
    Posts
    11
    Hm.. I'm running Windows XP... i found the declaration of the function in winbase.h.. it's there.. i'm just not able get it to compile. i also tested this on visual studio.net.. it seems to have the same problem.. one thing strange i did recongized was.. I accidentally put the source code (from above MSDN link) into a .h file? and it compiled without complaining.. i'm not sure what exactly is the problem of an NT system.. since most of my friends has XP/2000 machines i wasn't able to get a 98 system to test it on... you think u can let me know exactly how i can fix the problem?

  6. #6
    Registered User NewtonApple's Avatar
    Join Date
    Aug 2001
    Posts
    11
    hm.. seems like i forgot to define _WIN32_WINNT to 0x0501.. but now when i define this, i introduced a new problem.. it seems like this defintion blocks off my winsock2.h.. anyone knows why? im not very familiar with the whole win32 mechanism.. so please point me to the right direction.. thanks again 4 ur help.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> blocks off my winsock2.h..

    Are you linking the Winsock library, (ws2_32.lib)? You need to add it to the list of libraries, Project->Settings->Link Tab, then add the library to the end of the list in the "Object/Library modules" box.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Registered User NewtonApple's Avatar
    Join Date
    Aug 2001
    Posts
    11
    Yea, ws2_32.lib was linked.. it's just that when i define _WIN32_WINNT.. it some how blocks off winsock2.h. i'm not exactly what's the problem.

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    The source you cited at MSDN would not compile for me without NT 0x0400, but did afterwards, as did a call to WSAStartup().

    code.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Registered User NewtonApple's Avatar
    Join Date
    Aug 2001
    Posts
    11
    hm... i finally got it to work.. the order of my includes makes hell of a difference..

    then:
    Code:
     
    #include <winsock2.h>
    #include <windows.h>
    now:
    Code:
    #include <windows.h>
    #include <winsock2.h>
    i'm not sure why the order of my includes would have such an effect. i assume it's probably something defined in winsock2.h or windows.h. i'd love to hear the reason if anyone cares to explain. for now, im happy that it finally compiles!

  11. #11
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    winsock2.h isnt done very well.....it includes windows.h so you dont need to include windows.h at all

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21