Solved

timeSetEvent()

Posted on 1997-06-19
11
801 Views
Last Modified: 2013-12-03
I have examples of seting up a timer and have followed the code exactly. I am not calling it from MFC DLL InitInstance(). When my program runs it hangs when it tries to set up the timer. When I comment timeSetEvent() out it works (without a timer though and I need one).I made the CALLBACK procedure do nothing and it still didn't work. I use Borland C++ 5.01 and programming for Windows 95. I am at a loss, please help./*
      the timer function
*/
void CALLBACK TimerFunc( UINT wID, UINT wUser, DWORD dwUser, DWORD dw1, DWORD dw2 )
{
        if( PostPending == FALSE )
     {
                 PostPending = TRUE;
         PostMessage( hWndMain, WM_USER, 0, (DWORD)0 );
     }
     else
     {
                 timerTicksMissed++;
     }
        UNREFERENCED_PARAMETER(dw1);
     UNREFERENCED_PARAMETER(dw2);
     UNREFERENCED_PARAMETER(dwUser);
     UNREFERENCED_PARAMETER(wUser);
     UNREFERENCED_PARAMETER(wID);
} // TimerFunc

static void SetTime( void )
{
    TIMECAPS       caps;

    timeGetDevCaps( &caps, sizeof(caps) );
    ticksPerSecond = 1000 / caps.wPeriodMin;

    timeBeginPeriod( 1000 / ticksPerSecond );

    timerid = timeSetEvent( ( 1000 / ticksPerSecond ), ( 1000 / ticksPerSecond ), TimerFunc, (DWORD) 0, (UINT) TIME_PERIODIC );


}
0
Comment
Question by:Grub
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 

Author Comment

by:Grub
ID: 1398635
Edited text of question
0
 
LVL 23

Expert Comment

by:chensu
ID: 1398636
How did you use timeSetEvent? Can you show the code?
0
 

Author Comment

by:Grub
ID: 1398637
Edited text of question
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:Grub
ID: 1398638
sorry I didn't include the code the first time around. I hope it helps you answer my question.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1398639
It seems all ok. I've tested this code on NT4.0 and 95 - all works fine!
0
 
LVL 23

Expert Comment

by:chensu
ID: 1398640
It seems that there is nothing wrong with the code showed here. You can reduce your code to find out where the problem is. You can try the following code. Simply create a window, call SetMMTimer() when receiving WM_CREATE and ReleaseMMTimer() when receiving WM_DESTROY. You may need to modify some code (VERIFY, AfxMessageBox) for Borland C++.


DWORD m_dwCount;
UINT m_nRes;
UINT m_nMMTimerID;

//-----------------------------------------------------------------------------
BOOL SetMMTimer()
{
    m_dwCount = 0;

    TIMECAPS caps;
    VERIFY(::timeGetDevCaps(&caps, sizeof(caps)) == TIMERR_NOERROR);

    m_nRes = caps.wPeriodMin;

    VERIFY(::timeBeginPeriod(m_nRes) == TIMERR_NOERROR);

    m_nMMTimerID = ::timeSetEvent(m_nRes, m_nRes,
                                TimeProc,
                                (DWORD)&m_dwCount,
                          TIME_PERIODIC);
      
    if (m_nMMTimerID == 0)
      ::AfxMessageBox("timeSetEvent failed.");

    return TRUE;
}
//-----------------------------------------------------------------------------
void ReleaseMMTimer()
{
    if (m_nMMTimerID != 0)
    {
      // kill the periodic timer event
      VERIFY(::timeKillEvent(m_nMMTimerID) == TIMERR_NOERROR);
      m_nMMTimerID = 0;
    }

    VERIFY(::timeEndPeriod(m_nRes) == TIMERR_NOERROR);

    CHAR chBuf[16];
    ::wsprintf(chBuf, "%lu", m_dwCount);
    ::AfxMessageBox(chBuf);
}
//-----------------------------------------------------------------------------
void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD dwUser,
                   DWORD dw1, DWORD dw2)
{
    (*(LPDWORD)dwUser)++;
}
//-----------------------------------------------------------------------------

0
 

Author Comment

by:Grub
ID: 1398641
Sorry chensu but I tried the code you gave me (with changes) and it still hangs. The code examples I have say that WINMM.LIB should be linked in, however the fact that it compiles means that it is being linked in automatically, right? I couldn't find WINMM.LIB anywhere on my harddrive (only the DLL) so I created one using IMPLIB and linked that in, no luck still hangs. Maybe I should try and get WINMM.LIB ?
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1398642
For Visual C++, winmm.lib is not linked by default. Anyway, winmm.lib should be there. It is likely that there is something wrong with your compiler. You'd better reinstall it. The code I showed you works fine on my computer.
0
 

Author Comment

by:Grub
ID: 1398643
By coincidence I just finished reinstalling Borland C++ 5.01 and then did a search for winmm.lib. Still not found except for the one I created using ImpLib. I might have a look on the Borland Site. Thanks for your help anyway.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1398644
Borland C++ does not use separate Window's import libraries. It just uses the single large import32.lib . Import32.lib includes winmm.lib .
0
 

Author Comment

by:Grub
ID: 1398645
Thanks for all your help, but I have worked out why the code wasn't working. It does. I ran the executable without from explorer and it worked fine with the timeSetEvent() in. I have come to the conclussion that Borland somehow dissables timers that call a callback function. When I want to run my program I have to compile it without running it and then exit borland and run it from explorer. If anyone knows why Borland exibits this behaviour I would like to know how to stop it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question