?
Solved

multimedia timers in vc++ 32 bit

Posted on 1998-07-23
6
Medium Priority
?
490 Views
Last Modified: 2006-11-17
HELP!!!
I'm writing an app to compose semi random midi music and am having problems getting my head around the documentation regarding multimedia timers in c++. No probs with generating the notes and storing in a list but I need to set up a timer for the "time to next note" with a callback function to take a pointer to the list and play that note with a midiOutShortMsg command. If anyone has any code which would demonstrate this or indeed anything which demonstrates how the callback is called and a pointer passed to it I would be eternally grateful.

From the documentation I've seen it's not clear whether the callback function has to be in a fixed code segment in a dll or whether it's ok to have it in the main body of the code.

Any ideas? Thanks in advance.

Ben
PS. I'm using vc++ standard ed. version 4.00

b.g.shirley@eee.salford.ac.uk
ben@spangles.demon.co.uk
0
Comment
Question by:benjo
[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
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1168424
The callback function can be in the main code or in the DLL.  Don't worry.
0
 
LVL 23

Accepted Solution

by:
chensu earned 800 total points
ID: 1168425
Here is an example of how to use the Multimedia Timer Functions. In Win32, the callback function does not need to be in a DLL.

//-----------------------------------------------------------------------------
BOOL CTestWnd::SetMMTimer()
{
    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,
                                  0,
                                  TIME_PERIODIC);
   
    if (m_nMMTimerID == 0)
        ::AfxMessageBox("timeSetEvent failed.");

    return TRUE;
}
//-----------------------------------------------------------------------------
void CTestWnd::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);
}
//-----------------------------------------------------------------------------
void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
    //...
}
//-----------------------------------------------------------------------------
0
 

Author Comment

by:benjo
ID: 1168426
Thanks Chensu,
I'll give that a try soon as I get into work Monday am. I was getting errors on the third argument of timeSetEvent up to now. Tried setting up a pointer to the function timrproc() but the compiler said it couldn't convert from a _cdecl* to a _stdcall*. Tried all sorts of things but couldn't get the damn thing to declae right. Any idea why that might have been and will how will I have to declaere TimeProc in your example?

Thanks again


Ben
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:benjo
ID: 1168427
at least I'm jus' down to 2 errors now! Apart from my typoing that ios.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1168428
Define TimeProc as a static member function of the class or a global function. A member function of a class has an implicit parameter (the this pointer) so that the function prototype does not match.
0
 

Author Comment

by:benjo
ID: 1168429
To Chensu,
Many, many thanks, that's solved my problem. I guess from your answers that in 16 bit windows the callback DID have to be in a dll?
I guess that's where I got that idea from if that's the case. The origins of the app were ported from a vc++ v1 app.

Thanks again!

Ben
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

777 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