Can I use a SetTimer() API in a console C++ application?(我可以在控制台 C++ 应用程序中使用 SetTimer() API 吗?)
问题描述
我有一个控制台应用程序,它使用一个 DLL 文件,该文件使用 SetTimer() 调用来创建一个计时器并在其内部触发一个函数.电话如下:
I have a console application that is using a DLL file that uses a SetTimer() call to create a timer and fire a function within itself. The call is below:
SetTimer((HWND)NULL, 0, timer_num, (TIMERPROC)UnSyncMsgTimer)) == 0)
它期望接收计时器消息,但这从未发生.我假设因为我的是一个控制台应用程序而不是一个标准的 Windows GUI 应用程序(就像最初使用 DLL 文件的地方).这会阻止 DLL 文件功能的关键部分工作.
It is expecting to receive timer messages, but this never happens. I assume because mine is a console application and not a standard Windows GUI application (like where the DLL file was originally used). This stops a key part of the DLL files functionality from working.
我的应用程序需要保持控制台应用程序,我不能更改 DLL.
My application needs to stay a console application, and I cannot change the DLL.
是否有解决方法可以使这项工作正常进行?
Is there a work around to make this work?
推荐答案
您可以使用 CreateTimerQueueTimer 函数
HANDLE timer_handle_;
CreateTimerQueueTimer(&timer_handle_, NULL, TimerProc, user_object_ptr, 10, 0, WT_EXECUTEDEFAULT);
//callback
void TimerProc(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
{
user_object* mgr = (user_object*) lpParameter;
mgr->do();
DeleteTimerQueueTimer(NULL, timer_handle_, NULL);
timer_handle_ = NULL;
}
这篇关于我可以在控制台 C++ 应用程序中使用 SetTimer() API 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我可以在控制台 C++ 应用程序中使用 SetTimer() API 吗?
基础教程推荐
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
