在msdn上的一个例子:
#include <windows.h>
#include <stdio.h>int main()
{
    HANDLE hTimer = NULL;
    LARGE_INTEGER liDueTime;    liDueTime.QuadPart=-100000000;    // Create a waitable timer.
    hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
    if (!hTimer)
    {
        printf("CreateWaitableTimer failed (%d)\n", GetLastError());
        return 1;
    }    printf("Waiting for 10 seconds...\n");    // Set a timer to wait for 10 seconds.
    if (!SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0))
    {
        printf("SetWaitableTimer failed (%d)\n", GetLastError());
        return 2;
    }    // Wait for the timer.    if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
        printf("WaitForSingleObject failed (%d)\n", GetLastError());
    else printf("Timer was signaled.\n");    return 0;
}在borland C和dev-c下,编译运行都没有任何问题,可是在VC下却不通过??
竟然说没有定义??实在是郁闷不知为何??

解决方案 »

  1.   

    define the _WIN32_WINNT macro as 0x0400 or later
    #define _WIN32_WINNET 0x0400
    in your cpp file or header filemay you succeed !
      

  2.   

    to vcforever(霓裳羽衣) : 在msdn上我也看到了这个,试过了,好像还是不行!我就纳闷为什么VC编译不过,而且无论是否使用MFC都不行!!!
      

  3.   

    应该把:
    #define _WIN32_WINNET 0x0400
    加在#include <windows.h>之前,最好是加在stdafx.h中,以防其他文件先include了windows.h
      

  4.   

    birth_chen(流星) :还是不对,问题好像不是在这儿!
    你们在VC下通过了吗??我这里是不行,还是提示没有定义!!!
      

  5.   

    有三个错误啊
    D:\s\kk.cpp(15) : error C2065: 'CreateWaitableTimer' : undeclared identifier
    D:\s\kk.cpp(15) : error C2440: '=' : cannot convert from 'int' to 'void *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    D:\s\kk.cpp(25) : error C2065: 'SetWaitableTimer' : undeclared identifier
      

  6.   

    就是这个错误!!怎么都弄不过去!
    可是我在borland C和dev-c一点问题也没有!!!
    实在是很纳闷!!
      

  7.   

    to  carbon107(&lt;软件开发思想.h&gt;) :呵呵,,是不是觉得邪门了?NND,我都郁闷了一下午!!不知道有没有哪只大鸟能搞定这个问题??
      

  8.   

    应该把:
    #define _WIN32_WINNET 0x0400
    加在#include <windows.h>之前,最好是加在stdafx.h中,以防其他文件先include了windows.h
    放在stdafx.h的最前面试试
      

  9.   

    哈哈,我正好在做这个东西
    在#include <windows.h>前面添上:
    #define _WIN32_WINNT 0x0501
      

  10.   

    至于你的第二个错误,我有个朋友也遇到了,暂时还不太清楚是怎么回事,你仔细检查下数据类型吧。
    我用的是VS2003,定义_WIN32_WINNT为0x0501后就可以顺利编译执行了,没有任何错误或警告。
      

  11.   

    谢谢thisisjjjj(Jeffry),问题搞定!!结贴!!