# How do you write callbacks?

**URL:** <https://qa.fmod.com/t/how-do-you-write-callbacks/11040>\
**Category:** FMOD Studio\
**Created:** [June 18, 2013, 6:22pm UTC](https://qa.fmod.com/t/how-do-you-write-callbacks/11040 "2013-06-18T18:22:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![markmarijnissen](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@markmarijnissen](https://qa.fmod.com/u/markmarijnissen)\
**Post date:** [June 18, 2013, 6:22pm UTC](https://qa.fmod.com/t/how-do-you-write-callbacks/11040/1 "2013-06-18T18:22:35Z")

</div>

OK, I am absolutely puzzled by this declaration:

```auto
typedef FMOD_RESULT (F_CALLBACK *FMOD_STUDIO_EVENT_CALLBACK)(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, void* parameters);
```

How do I declare a callback?

```auto
// in foo.h
class Foo {
    FMOD::Studio::EventInstance eventinstance;
    FMOD_RESULT onEvent(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, void* parameters); //????
    void bind();
}

// in foo.cpp
void Foo::bind() {
    eventInstance.setCallback(Foo::onEvent); //does not work ??? 
}

void Foo::onEvent(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, void* parameters) {
    // how do I access parameters?
}
```

Thanks for answering this newb question!

---

<div class="post-metadata">

**Author:** ![Guest](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@Guest](https://qa.fmod.com/u/Guest)\
**Post date:** [June 19, 2013, 8:37am UTC](https://qa.fmod.com/t/how-do-you-write-callbacks/11040/2 "2013-06-19T08:37:36Z")

</div>

Your callback needs to have F\_CALLBACK in the declaration. If it’s a class member function, it also needs to be static:

```auto
    static FMOD_RESULT F_CALLBACK onEvent(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, void* parameters);
```

---

<div class="post-metadata">

**Author:** ![skylar1992](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/skylar1992/32/3456_2.png) [@skylar1992](https://qa.fmod.com/u/skylar1992)\
**Post date:** [August 5, 2022, 5:17am UTC](https://qa.fmod.com/t/how-do-you-write-callbacks/11040/3 "2022-08-05T05:17:59Z")

</div>

Sorry for bumping this super old post up, I have a similar question and figured this is better than starting a completely new topic. I understand the static and F\_CALLBACK part, still hope to know hot to pass parameters into the callback function. There’s nowhere in the `setCallback` function to pass in a `void*` for the callback function’s `parameters` argument.

---

<div class="post-metadata">

**Author:** ![Bnnoy](https://avatars.discourse-cdn.com/v4/letter/b/dbc845/32.png) [@Bnnoy](https://qa.fmod.com/u/Bnnoy)\
**Post date:** [August 5, 2022, 11:34am UTC](https://qa.fmod.com/t/how-do-you-write-callbacks/11040/4 "2022-08-05T11:34:47Z")

</div>

You would want to use `setUserData()` for this, it allows you to pass arbitrary data as void\* that will be sent back everytime a callback is triggered (on the instance you called `setUserData()` on)
