如何解决在mingw编译器上的Windows中使用微秒计时器吗?
我想设置一个计时器。时间到时,应调用回调函数。但是时间以微秒为单位。我在Windows上找到了多媒体计时器,但是我在Windows上使用mingw编译器。那么在Windows上是否有任何与mingw编译器一起使用的方法。
我尝试使用https://docs.microsoft.com/en-us/windows/win32/sync/using-timer-queues
但是我有一个错误:“未在此范围内声明CreateTimerQueue()”如何解决此问题?
#include <windows.h>
#include <stdio.h>
HANDLE gDoneEvent;
VOID CALLBACK TimerRoutine(PVOID lpParam,BOOLEAN TimerOrWaitFired)
{
if (lpParam == NULL)
{
printf("TimerRoutine lpParam is NULL\n");
}
else
{
// lpParam points to the argument; in this case it is an int
printf("Timer routine called. Parameter is %d.\n",*(int*)lpParam);
if(TimerOrWaitFired)
{
printf("The wait timed out.\n");
}
else
{
printf("The wait event was signaled.\n");
}
}
SetEvent(gDoneEvent);
}
int main()
{
HANDLE hTimer = NULL;
HANDLE hTimerQueue = NULL;
int arg = 123;
// Use an event object to track the TimerRoutine execution
gDoneEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
if (NULL == gDoneEvent)
{
printf("CreateEvent failed (%d)\n",GetLastError());
return 1;
}
// Create the timer queue.
hTimerQueue = CreateTimerQueue();
if (NULL == hTimerQueue)
{
printf("CreateTimerQueue failed (%d)\n",GetLastError());
return 2;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。