Solved

timeSetEvent()

Posted on 1997-06-19
11
778 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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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