Solved

multimedia timers in vc++ 32 bit

Posted on 1998-07-23
6
469 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
  • 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 200 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now