[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

multimedia timers in vc++ 32 bit

Posted on 1998-07-23
6
Medium Priority
?
500 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
Industry Leaders: 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!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.
Suggested Courses

650 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