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
Solved

multimedia timers in vc++ 32 bit

Posted on 1998-07-23
6
477 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 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.

808 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