0
0

Hi.
Can anyone help me how to use in VC++ a member-function of a class as Callback-Function? e.g. for Stream_SetEndCallback()?
Thanks.

  • You must to post comments
0
0

Hi Brett.

Thanks for Your answer. But doesn’t that mean, callbacks are unusable in VC++?

Prem.

  • You must to post comments
0
0

you can always use the param in the callback functions as a pointer to your objects, think i explained the concept sometime ago, use search facility…

  • You must to post comments
0
0

do whatever to your stream, then set the callback to something like this

[code:v5dkxez4]
signed char (fpt)(FSOUND_STREAM, void*, int, int)= &::StreamCB;
FSOUND_Stream_SetEndCallback(m_oStream, fpt, myID);
[/code:v5dkxez4]

i could have passed a pointer b:v5dkxez4this[/b:v5dkxez4] but i choose an id so i can check if it’s valid when i get the callback. depends on your implementation.

then the callback…

[code:v5dkxez4]
signed char StreamCB(FSOUND_STREAM* pStream, void buff, int len, int id)
{
SoundObject
pSound = engine.sound.find(id);

 if (pSound)
 {
      pSound->SetFlag(kSoundCompletionFlag);
 }

 return 1;

}
[/code:v5dkxez4]

here i get back into ‘object space’ by looking up the id of the sound that’s finishing. also, i only set a flag because one should return to fmod asap. then i’ll handle the completion event in the event loop. of course, if you’re familiar with multitheading, you can make this completion event get handled much quicker than polling in the event loop. this is just a simple example of how to get back into your object. this is off topic, but if you only have one main thread, then the callback could schedule an event instead. for example,

[code:v5dkxez4]
signed char StreamCB(FSOUND_STREAM* pStream, void *buff, int len, int id)
{
engine.sound.events.schedule(id, kSoundCompletionEvent);

 return 1;

}
[/code:v5dkxez4]

in this case, the sound system has an event queue, so adding the event will trigger it when appropriate, as opposed to polling all the sound objects for their state (much better this way).

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.