我可以在控制台 C++ 应用程序中使用 SetTimer() API 吗? [英] Can I use a SetTimer() API in a console C++ application?

查看:24
本文介绍了我可以在控制台 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 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆