wave callbacks - Programmer

This is a discussion on wave callbacks - Programmer ; Hi, I can implement a waveOutProc callback. But I can't understand how to incorporate into my class as it seems that the callback can't be a class member. When the callback fires I need to change variables in the class ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: wave callbacks

  1. wave callbacks

    Hi,

    I can implement a waveOutProc callback. But I can't understand how to
    incorporate into my class as it seems that the callback can't be a class
    member. When the callback fires I need to change variables in the class but
    can't access them as the callback isn't a member function.

    Some old MS code "CWaveOut.cpp" uses CreateSemaphore, ReleaseSemaphore etc.
    Is this the only way? Is this still supported in XP & Vista?

    Any help appreciated, thanks.

    Paul



  2. Re: wave callbacks

    pf wrote:
    > Hi,
    >
    > I can implement a waveOutProc callback. But I can't understand how to
    > incorporate into my class as it seems that the callback can't be a class
    > member. When the callback fires I need to change variables in the class but
    > can't access them as the callback isn't a member function.
    >
    > Some old MS code "CWaveOut.cpp" uses CreateSemaphore, ReleaseSemaphore etc.
    > Is this the only way? Is this still supported in XP & Vista?
    >
    > Any help appreciated, thanks.
    >
    > Paul
    >
    >


    The callback can't be a class member because the win API is C, and
    cannot match C++ calling conventions. You can pass 'this' as the
    instance parameter to waveOutOpen, and it will be passed to your
    callback function. With that pointer you can call a member function.

    But when you use a callback function there are a whole lot of things you
    cannot do in it, as documented, because you are called in a system
    thread context. Using a callback event or window message avoids that
    set of restrictions. If you want to use the event you would use
    CreateEvent and WaitForSingleObject.

    --
    Scott McPhillips [VC++ MVP]


+ Reply to Thread