在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下却不通过??
竟然说没有定义??实在是郁闷不知为何??
#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下却不通过??
竟然说没有定义??实在是郁闷不知为何??
#define _WIN32_WINNET 0x0400
in your cpp file or header filemay you succeed !
#define _WIN32_WINNET 0x0400
加在#include <windows.h>之前,最好是加在stdafx.h中,以防其他文件先include了windows.h
你们在VC下通过了吗??我这里是不行,还是提示没有定义!!!
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
可是我在borland C和dev-c一点问题也没有!!!
实在是很纳闷!!
#define _WIN32_WINNET 0x0400
加在#include <windows.h>之前,最好是加在stdafx.h中,以防其他文件先include了windows.h
放在stdafx.h的最前面试试
在#include <windows.h>前面添上:
#define _WIN32_WINNT 0x0501
我用的是VS2003,定义_WIN32_WINNT为0x0501后就可以顺利编译执行了,没有任何错误或警告。