Solved

multimedia timers in vc++ 32 bit

Posted on 1998-07-23
6
464 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 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

17 Experts available now in Live!

Get 1:1 Help Now