# FMOD stream call back functions

## Recommended Posts

Hi! I can't figure out what am I doing wrong. Here is how I specify end callback function :
signed char StreamEndCallback(SOUND_STREAM *stream, void *buff, int len, int param)
{
return 1;
}

When I call ...
FSOUND_Stream_SetEndCallback(tag.m_pStream, StreamEndCallback,  0);

... I am getting a following error (MSVC++ 6.0) :
error C2664: 'FSOUND_Stream_SetEndCallback' : cannot convert parameter 2 from 'signed char (struct FSOUND_STREAM *,void *,int,int)' to 'signed char (__stdcall *)(struct FSOUND_S
TREAM *,void *,int,int)'

What is wrong? I was looking at some sample code and everything seems to be identical. Thanks in advance! -------------

##### Share on other sites
Try adding a & before the functio name like FSOUND_Stream_SetEndCallback(tag.m_pStream, &StreamEndCallback, 0)

You can also try specifically declaring it as __stdcall, I think MSVC used __cdecl by default.

##### Share on other sites

Quote:
 Original post by GyrboTry adding a & before the functio name like FSOUND_Stream_SetEndCallback(tag.m_pStream, &StreamEndCallback, 0)

Unfortunately, this way I get an error.

Quote:
 You can also try specifically declaring it as __stdcall, I think MSVC used __cdecl by default.

I've tried to declaring the function as __stdcall but it doesn't work anyway. :/ Is it possible that this declaration can be skipped by the compiler (some settings etc...) ?

Thanks!

------------

##### Share on other sites
If you have the function prototype in a header file, make sure you add the __stdcall there (too).

It's always helpful if you post the actual error messages ;).

##### Share on other sites
Hey, Gyrbo.

This morning I woke up and went to a hairdresser. Then, I took some time to practice a guitar and when I finished I discovered that none of my (two) brothers is occupying the computer. I thought : 'No way, I can stay at this point for too long'. I launched the compiler and started to think. Suddenly, I realized a following thing : 'How can FMOD call the callback function when it's included in my own class?'. I figured out that if I make a callback function static the code compiles without errors (don't know if it really works, anyway). Unfortunately, that's not the end of my question. Even though the code 'theoriticaly' works, I am getting this error :
error C2352: 'FMODSoundSystem::PlaylistNextSong' : illegal call of non-static member function

How can I call a member functions within a static member-function (in some elegant way, of course) ?

Thanks! :)

PS. Because of your effort, you deserved some positive rating, Gyrbo. :)

-------------

##### Share on other sites
Static member functions aren't really meant to call other functions of that class. You could work around that by making your class a singleton (or just storing an instance of it in a global/static variable). I haven't used them before, but functors could probably also work for this.
You probably have a flaw in your design somewhere if you have to call a non-static function from a static one.

I'm not really familiar with fmod, so I can't really help you on that side.

##### Share on other sites
Quote:
 Original post by GyrboI'm not really familiar with fmod, so I can't really help you on that side.

It's not an FMOD question now really. Thanks, anyway.

##### Share on other sites
Hello,

Here what to do :

1) Put the callback prototype on top of your file .cpp just after #include "myClass.h" and before class constructor myClass:myClass()...

ex: FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, ...);

2) Put the callback function at the end of your .cpp after all the methods

ex:
{
...
}

3) Declare the variables you need to control that are inside your callback function as global on top of your .cpp (after the #include"myClass")

4) Modify the variables of 3) as needed with methods of your class.

And voilà!

Hope it will work for you!

Firsbruno

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627665
• Total Posts
2978524

• 10
• 10
• 12
• 22
• 13