Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are few problems with your program:</p> <ol> <li>C programs do end when they leave <code>main()</code> so there is no time when the timer can occur.</li> <li><p>Win32 timers need the message pump (see below) to be working, as they are implemented through <code>WM_TIMER</code> message, even when they are not associated with any window, and if you provide function callback.</p> <blockquote> <p>When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER.</p> <p><sub>Source: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644906%28v=vs.85%29.aspx" rel="noreferrer">MSDN: SetTimer function</a></sub></p> </blockquote></li> <li><p>The callback function has bad prototype. See <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644907%28v=vs.85%29.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/ms644907%28v=vs.85%29.aspx</a></p> <pre><code>void CALLBACK f(HWND hwnd, UINT uMsg, UINT timerId, DWORD dwTime) { printf("Hello"); } int main() { MSG msg; SetTimer(NULL, 0, 1000*60,(TIMERPROC) &amp;f); while(GetMessage(&amp;msg, NULL, 0, 0)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } return 0; } </code></pre></li> </ol> <p>(Note this example program never ends, instead, real program should have some additional logic to do so by sending <code>WM_QUIT</code>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload