<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx</link><description>It's time for another "APIs you never heard of" article :) This time, I'd like to talk about the time* APIs. The time* APIs are a set of 7 APIs built into the windows multimedia extensions (winmm.dll). They provide a rudimentary set of timer functions</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462507</link><pubDate>Thu, 08 Sep 2005 21:09:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462507</guid><dc:creator>PatriotB</dc:creator><description>Thanks for the entry Larry.  It's always refreshing to see little-known APIs getting mentioned in the present day.&lt;br&gt;&lt;br&gt;I just took a look at the timeBeginPeriod documentation and got a chuckle out of the return values: &amp;quot;Returns TIMERR_NOERROR if successful or TIMERR_NOCANDO if the resolution specified in uPeriod is out of range.&amp;quot;&lt;br&gt;&lt;br&gt;No can do!</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462524</link><pubDate>Thu, 08 Sep 2005 21:50:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462524</guid><dc:creator>SuperBK</dc:creator><description>Hey-I use timeSetEvent! What is the accuracy of the Timers in the Timer Queues?  I thought the multi media timers were supposed to be high resolution timers. Also, I can't get the example at &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/using_timer_queues.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/using_timer_queues.asp&lt;/a&gt; to compile. The error is&lt;br&gt;error C2664: 'CreateTimerQueueTimer' : cannot convert parameter 3 from 'void (void *,int)' to 'void (__stdcall *)(void *,unsigned char)'</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462525</link><pubDate>Thu, 08 Sep 2005 22:00:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462525</guid><dc:creator>LarryOsterman</dc:creator><description>timeSetEvent has the same resolution as all the other waitable objects in the system.&lt;br&gt;&lt;br&gt;On all NT versions, the multimedia timers use the NT internal timer infrastructure, which is the exact same infrastructure that's used by the timer queue timers.  For Win 3.1, it may have used a higher resolution timer.&lt;br&gt;&lt;br&gt;However, on closer inspection, it appears that the timeSetEvent API will call timeBeginPeriod to set the system clock frequency to the resolution of the timer.  I'll update the article.&lt;br&gt;&lt;br&gt;For your compiler error, it appears that your callback function isn't declared with the correct function parameters - it needs to be a stdcall function that takes a LPVOID and a BYTE parameter, not a &amp;lt;whatever&amp;gt; function that takes a LPVOID and an int parameter.  I'll talk to the owner of the API.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462549</link><pubDate>Thu, 08 Sep 2005 22:39:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462549</guid><dc:creator>Purplet [italy]</dc:creator><description>Interesting comparison of timing function at &lt;a rel="nofollow" target="_new" href="http://developer.nvidia.com/object/timer_function_performance.html"&gt;http://developer.nvidia.com/object/timer_function_performance.html&lt;/a&gt; .&lt;br&gt;Strangely however, timeGetTime() and GetTickCount() perform completely different (and not by a small margin).. which is odd if they are really equivalent like you say. &lt;br&gt;&lt;br&gt;Anyway in every place I worked, timeGetTime() was quite a popular function :)</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462571</link><pubDate>Thu, 08 Sep 2005 23:31:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462571</guid><dc:creator>LarryOsterman</dc:creator><description>Fascinating purplet.  It turns out that GetTickCount returns the tick count multiplied by the clock frequency, while TimeGetTime returns the &amp;quot;interrupt time&amp;quot;, which is a somewhat different calculation (and is apparently not updated as frequently).&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462658</link><pubDate>Fri, 09 Sep 2005 02:27:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462658</guid><dc:creator>Chris Lundie</dc:creator><description>With CPU's that can change their clock frequency (often seen in laptops) I'm never quite certain about the accuracy of timer functions.</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462758</link><pubDate>Fri, 09 Sep 2005 06:14:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462758</guid><dc:creator>LarryOsterman</dc:creator><description>Chris, a good and relevent question.  The simple answer is that NT guarantees that the timers are stable, which means that it doesn't matter what the clock frequency does, the timer frequency won't change.&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462790</link><pubDate>Fri, 09 Sep 2005 08:19:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462790</guid><dc:creator>Phaeron</dc:creator><description>Larry, did you get GetTickCount() and timeGetTime() mixed up in the comment to purplet? I thought it was the other way around, that GetTickCount() returns interrupt-counted time (10ms/55ms), whereas timeGetTime() returns timer-based time (8254 PIT @ 1.1MHz, usually).&lt;br&gt;&lt;br&gt;Also, the current online documentation for timeSetEvent() seems rather scrambled. It says that the function only exists on Windows XP, even though it's been around since Windows 95. TIME_KILL_SYNCHRONOUS seems to have appeared silently -- it wasn't in my October 2000 MSDN Library -- but it isn't marked as requiring a particular OS version. I remember having to work around that missing flag by killing the periodic event from within the callback itself in order to avoid a race.&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462803</link><pubDate>Fri, 09 Sep 2005 09:23:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462803</guid><dc:creator>Chris Lundie</dc:creator><description>Thanks, Larry, I think it was this blog entry that got me concerned about it: (beginning near the bottom with &amp;quot;on certain mobile processors the tick frequency is not constant...&amp;quot;&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://www.interact-sw.co.uk/iangblog/2005/03/31/nanoperf"&gt;http://www.interact-sw.co.uk/iangblog/2005/03/31/nanoperf&lt;/a&gt;&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462829</link><pubDate>Fri, 09 Sep 2005 10:34:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462829</guid><dc:creator>Centaur</dc:creator><description>I once needed a time measuring facility to assess performance of my code. The multimedia timer API turned out to be surprisingly lightweight in comparison with QueryPerformanceCounter, and more precise than GetTickCount.</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462857</link><pubDate>Fri, 09 Sep 2005 14:24:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462857</guid><dc:creator>Drew</dc:creator><description>Suggest: There was internal discussion recently about code that raises 1st chance exceptions and why not to do that even though technically it's legit. Could make for an interesting post (series of posts?).&lt;br&gt;Actually another one I'd like to see is &amp;quot;why you really want that would-be service in kernel mode vs. why you really want it to be a service&amp;quot;.&lt;br&gt;I know the answers I'd give, but you're both more experienced than I am and seem to swear less in public than I do. I'd rather see your explanation.&lt;br&gt;&lt;br&gt;Your suggestion box doesn't seem to have a comments link (grumble - where in Product Studio do I file *that* bug?), so I'm posting these here.</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462878</link><pubDate>Fri, 09 Sep 2005 16:02:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462878</guid><dc:creator>Dave</dc:creator><description>&amp;quot;NT guarantees that the timers are stable&amp;quot;&lt;br&gt;&lt;br&gt;Except when it doesn't:&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q274323"&gt;http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q274323&lt;/a&gt;&lt;br&gt;&lt;br&gt;I do not like bad hardware chips, I do not want their timer slips. I do not want them on my bus, I do not want them erroneous.</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462889</link><pubDate>Fri, 09 Sep 2005 16:18:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462889</guid><dc:creator>LarryOsterman</dc:creator><description>Dave, good point.&lt;br&gt;&lt;br&gt;Centaur, QPC is heavyweight, and is documented as such.  timeGetTime is faster but much less accurate.&lt;br&gt;&lt;br&gt;I actually checked the code for timeGetTime and GetTickCount().  GetTickCount() takes the number of clock interrupts and multiplies it by the clock frequency.  timeGetTime() reads a field called the &amp;quot;interrupt time&amp;quot;, which is updated periodically by the kernel (I wasn't able to find out how frequently).&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462948</link><pubDate>Fri, 09 Sep 2005 18:39:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462948</guid><dc:creator>Aaron</dc:creator><description>&amp;gt; I'm not sure if I know of any reason to ever call the MME versions of these functions :).  &lt;br&gt;&lt;br&gt;How about if you want your code to still be able to run on Win9x?&lt;br&gt;&lt;br&gt;I would LOVE to be able to stop having to consider Win9x, but about 15% of my customer base still runs some form of it (about 1% still runs Win95!)&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462978</link><pubDate>Fri, 09 Sep 2005 19:47:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462978</guid><dc:creator>Ulric</dc:creator><description>So your blog is not correct and will mislead the people who come across it.. timeGetTime is not obsolete, and it isn't effectvly identical to GetTickCount, which is the point of the first paragraph after the bullet list.  And the problem Raymond raises about pulse event doesn't affect timeSetEvent.</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#462999</link><pubDate>Fri, 09 Sep 2005 20:20:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462999</guid><dc:creator>M Knight</dc:creator><description>The docs for timeGetTime tell you to monkey with timeBeginPeriod &amp;amp; timeGetDevCaps to improve timeGetTime's resolution. </description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#463145</link><pubDate>Sat, 10 Sep 2005 00:51:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:463145</guid><dc:creator>LarryOsterman</dc:creator><description>Ulric, timeGetTime returns millisecond resolution time that's at a lower resolution than GetTickCount().  Under what circumstances would you want to use it?&lt;br&gt;&lt;br&gt;The think is that timeBeginPeriod will improve the resolution of GetTickCount() as well.&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#463232</link><pubDate>Sat, 10 Sep 2005 02:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:463232</guid><dc:creator>Ulric</dc:creator><description>I see your point, I'm thinking about the fact  timeGetTime is more accurate on Win9x by default.  On Win2k and up, I would hesitate recommend using GetTickCount over timeGetTime if timeBeginPeriod happens to affect GetTickCount as well, since the two API are unrelated and that behaviour is not documented. </description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#463255</link><pubDate>Sat, 10 Sep 2005 03:59:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:463255</guid><dc:creator>Doug</dc:creator><description>The TimeProc documentation is out of date too: it says &amp;quot;Applications should not call any system-defined functions from inside a callback function, except for PostMessage, timeGetSystemTime, timeGetTime, timeSetEvent, timeKillEvent, midiOutShortMsg, midiOutLongMsg, and OutputDebugString.&amp;quot; This seems to be a hangover from the Win16 days when TimeProc was called from the interrupt service routine.</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#463279</link><pubDate>Sat, 10 Sep 2005 05:56:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:463279</guid><dc:creator>M Knight</dc:creator><description>Both GetTickCount &amp;amp; timeGetTime return a value in milliseconds as an integer. And after using timeBeginPeriod you are better off using the low latancy time function.&lt;br&gt;&lt;br&gt;Also the msdn docs for GetTickCount say;&lt;br&gt;&amp;quot;If you need a higher resolution timer, use a multimedia timer or a high-resolution timer&amp;quot;.</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#463375</link><pubDate>Sat, 10 Sep 2005 17:29:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:463375</guid><dc:creator>LarryOsterman</dc:creator><description>Doug, that's actually a comment that's on all the MME callback functions, because they are all highly prone to deadlock.&lt;br&gt;</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#465293</link><pubDate>Wed, 14 Sep 2005 04:54:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:465293</guid><dc:creator>Norman Diamond</dc:creator><description>Another timer API:  item 2 on the list at&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://www.tangentsoft.net/wskfaq/articles/lame-list.html"&gt;http://www.tangentsoft.net/wskfaq/articles/lame-list.html&lt;/a&gt;&lt;br&gt;&lt;br&gt;Actually that used to be a common trick on certain non-Windows systems to get a sleep for a shorter duration than the minimum available from the legitimate sleeping API.  It's a lame trick on Windows because all those developers who migrated from that certain other OS (where sockets were invented) weren't aware of the enormously powerful APIs that Windows provided in those days.</description></item><item><title>re: APIs you never heard of - the Timer APIs</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#474378</link><pubDate>Tue, 27 Sep 2005 16:42:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:474378</guid><dc:creator>Lucas</dc:creator><description>Simple way to change the resolution of the timer on your system without having to change your code... &lt;a rel="nofollow" target="_new" href="http://users.tpg.com.au/lucash/"&gt;http://users.tpg.com.au/lucash/&lt;/a&gt;&lt;br&gt;</description></item><item><title> Larry Osterman s WebLog APIs you never heard of the Timer APIs | Insomnia Cure</title><link>http://blogs.msdn.com/larryosterman/archive/2005/09/08/apis-you-never-heard-of-the-timer-apis.aspx#9709672</link><pubDate>Tue, 09 Jun 2009 00:56:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9709672</guid><dc:creator> Larry Osterman s WebLog APIs you never heard of the Timer APIs | Insomnia Cure</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://insomniacuresite.info/story.php?id=2014"&gt;http://insomniacuresite.info/story.php?id=2014&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>