惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
爱范儿
爱范儿
V
Visual Studio Blog
The Register - Security
The Register - Security
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
大猫的无限游戏
大猫的无限游戏
L
LangChain Blog
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
T
Threatpost
P
Proofpoint News Feed
美团技术团队
A
About on SuperTechFans
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog
Vercel News
Vercel News
L
Lohrmann on Cybersecurity
N
News and Events Feed by Topic
宝玉的分享
宝玉的分享
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
S
Security @ Cisco Blogs
AWS News Blog
AWS News Blog
SecWiki News
SecWiki News
I
InfoQ
PCI Perspectives
PCI Perspectives
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hacker News - Newest:
Hacker News - Newest: "LLM"
Latest news
Latest news
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Help Net Security
B
Blog RSS Feed
H
Hacker News: Front Page
雷峰网
雷峰网
Know Your Adversary
Know Your Adversary

博客园 - Silence

[转载]使用CPU时间戳进行高精度计时 [转载]VC实现CPU速度自测 自动刷新查询火车票脚本 北欧国旗的十字架 lu面 【转载】粤语翻译工具 异形魔方SQ1的暴力解法 [转载]聪明地使用Google的7个技巧 转载:“凤求凰”的解释,有才 【转】眼镜业内幕 专业操盘手的买卖法则 性格的英文单词 股东权益和权益比 音量控制面板项目说明 乘车指南 券商创设认购权证分析 调整出口关税对股价的影响 深市证券交易费用 沪市证券交易费用
[转载]CreateWaitableTimer和SetWaitableTimer函数
Silence · 2012-05-15 · via 博客园 - Silence

使用定时器的API函数CreateWaitableTimerSetWaitableTimer来实现了,这对API函数创建的时钟是比较精确的,可以达到100倍的10亿分之一秒,即100纳秒。
 
函数CreateWaitableTimerSetWaitableTimer声明如下:
 
WINBASEAPI
__out
HANDLE
WINAPI
CreateWaitableTimerA(
    __in_opt LPSECURITY_ATTRIBUTES lpTimerAttributes,
    __in     BOOL bManualReset,
    __in_opt LPCSTR lpTimerName
    );
WINBASEAPI
__out
HANDLE
WINAPI
CreateWaitableTimerW(
    __in_opt LPSECURITY_ATTRIBUTES lpTimerAttributes,
    __in     BOOL bManualReset,
    __in_opt LPCWSTR lpTimerName
    );
#ifdef UNICODE
#define CreateWaitableTimer CreateWaitableTimerW
#else
#define CreateWaitableTimer CreateWaitableTimerA
#endif // !UNICODE
 
 
WINBASEAPI
BOOL
WINAPI
SetWaitableTimer(
    __in     HANDLE hTimer,
    __in     const LARGE_INTEGER *lpDueTime,
    __in     LONG lPeriod,
    __in_opt PTIMERAPCROUTINE pfnCompletionRoutine,
    __in_opt LPVOID lpArgToCompletionRoutine,
    __in     BOOL fResume
    );
 
lpTimerAttributes是设置定时器的属性。
bManualReset是是否手动复位。
lpTimerName是定时器的名称。
hTimer是定时器的句柄。
lpDueTime是设置定时器时间间隔,当设置为正值是绝对时间;当设置为负数是相对时间。
lPeriod是周期。
pfnCompletionRoutine是设置回调函数。
lpArgToCompletionRoutine是传送给回调函数的参数。
fResume是设置系统是否自动恢复。
 
调用函数的例子如下:
#001 //创建定时器
#002  //蔡军生 2007/11/06 QQ:9073204 深圳
#003  int CreateTestTimer(void)
#004  {
#005         HANDLE hTimer = NULL;
#006         LARGE_INTEGER liDueTime;
#007 
#008         //设置相对时间为10秒。
#009         liDueTime.QuadPart = -100000000;
#010 
#011      ;   //创建定时器。
#012        hTimer = CreateWaitableTimer(NULL, TRUE, _T("TestWaitableTimer"));
#013         if (!hTimer)
#014         {              
#015               return 1;
#016         }
#017 
#018         OutputDebugString(_T("10秒定时器/r/n"));
#019 
#020         // 设置10秒钟。
#021        if (!SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0))
#022         {        
#023               //
#024               CloseHandle(hTimer);
#025               return 2;
#026         }
#027 
#028         //等定时器有信号。
#029         if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
#030         {
#031               OutputDebugString(_T("10秒定时器出错了/r/n"));   
#032               //
#033               CloseHandle(hTimer);
#034               return 3;
#035         }
#036         else
#037         {
#038               //10秒钟到达。
#039               OutputDebugString(_T("10秒定时器到了/r/n"));            
#040         }
#041 
#042         //
#043         CloseHandle(hTimer);
#044         return 0;
#045  }