# Error occurred when using FMOD\_FILE\_OPENCALLBACK!!

**URL:** <https://qa.fmod.com/t/error-occurred-when-using-fmod-file-opencallback/11198>\
**Category:** FMOD Studio\
**Created:** [October 31, 2013, 5:50am UTC](https://qa.fmod.com/t/error-occurred-when-using-fmod-file-opencallback/11198 "2013-10-31T05:50:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdkid1412](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@gdkid1412](https://qa.fmod.com/u/gdkid1412)\
**Post date:** [October 31, 2013, 5:50am UTC](https://qa.fmod.com/t/error-occurred-when-using-fmod-file-opencallback/11198/1 "2013-10-31T05:50:14Z")

</div>

I use the 1.1.11 version before and nothing wrong happened.

```auto
	FILE* file = NULL;
	fopen_s( &file, "Reign of the Septims.mp3", "rb" ); //read a file into the memory
	FMOD_CREATESOUNDEXINFO info;
	memset( &info, 0, sizeof( FMOD_CREATESOUNDEXINFO ) );
	info.cbsize = sizeof( FMOD_CREATESOUNDEXINFO );
	info.useropen = MyOpen;
	info.userclose = MyClose;
	info.userread = MyRead;
	info.userseek = MySeek;
system->createStream( (const char*)file, FMOD_DEFAULT, &info, &pTestSound1 );
//here's the callback 
FMOD_RESULT F_CALLBACK MyOpen( const char* name, int unicode, unsigned int *fileSize, void **handle, void** userData )
{
	if ( name )
	{
		FILE* pFile = (FILE*)name;

		fseek( pFile, 0, SEEK_END );
		*fileSize = ftell( pFile );
		fseek( pFile, 0, SEEK_SET );
		*handle = pFile;
		return FMOD_OK;
	}
	return FMOD_ERR_INVALID_PARAM;
}

FMOD_RESULT F_CALLBACK MyClose( void* handle, void* userData )
{
	if ( !handle )
	{
		return FMOD_ERR_INVALID_PARAM;
	}
	fclose( ( FILE* )handle );
	return FMOD_OK;
}

FMOD_RESULT F_CALLBACK MyRead( void* handle, void* buffer, unsigned int sizebytes, unsigned int* bytesread, void* userData )
{
	size_t haveRead = fread( buffer, 1, sizebytes, ( FILE* )handle );
	*bytesread = (unsigned int)haveRead;
	return FMOD_OK;
}

FMOD_RESULT F_CALLBACK MySeek( void* handle, unsigned int pos, void* userData )
{
	fseek( ( FILE* )handle, pos, SEEK_SET );
	return FMOD_OK;
}
```

I switch to the 1.2.5 version recently and change void\*\*userData to void\*userData.  
But Error Occurred!! Why? and how to fix it ?

---

<div class="post-metadata">

**Author:** ![gdkid1412](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@gdkid1412](https://qa.fmod.com/u/gdkid1412)\
**Post date:** [October 31, 2013, 6:26am UTC](https://qa.fmod.com/t/error-occurred-when-using-fmod-file-opencallback/11198/2 "2013-10-31T06:26:21Z")

</div>

I’m sorry, I do have a question but not for this reason. Shame on me.

```auto
//error occured when playing the sound
system->playSound( pTestSound1, ProxyMasterGroup, false, 0 );
```

It’s about this ProxyMasterGroup.  
I ask a question about the masterchannelgroup-\>SetMute does not work before,so I create a proxychannelgroup add to masterchannelgroup.  
Here’s how I get the proxychannelgoup. It’s nothing wrong in 1.1.11version.

```auto
				FMOD::Studio::ID busID = {0};
				FMOD_RESULT result = m_pFmodSystem->lookupBusID( "/ProxyMasterGroup",&busID ); //get my proxymastergroup
				if ( result != FMOD_OK )
				{
					return false;
				}

				FMOD::Studio::MixerStrip * mixer = new FMOD::Studio::MixerStrip; 
				result = m_pFmodSystem->getMixerStrip( &busID, loadingMode, mixer );
				if ( result != FMOD_OK )
				{
					return false;
				}

				result = mixer->getChannelGroup( &ProxyMasterGroup );
				if ( result != FMOD_OK )
				{
					return false;
				}
mixer->release(); //this line caused the error
```

I’m sorry again.  
So in the 1.2.5 version I can’t release the mixerstrip even though I just want the channelgroup in it?

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [November 11, 2013, 10:35pm UTC](https://qa.fmod.com/t/error-occurred-when-using-fmod-file-opencallback/11198/3 "2013-11-11T22:35:24Z")

</div>

> [@gdkid1412](#):
>
> I use the 1.1.11 version before and nothing wrong happened.
> 
> ```auto
> FILE* file = NULL;
> fopen_s( &file, "Reign of the Septims.mp3", "rb" ); //read a file into the memory
> FMOD_CREATESOUNDEXINFO info;
> memset( &info, 0, sizeof( FMOD_CREATESOUNDEXINFO ) );
> info.cbsize = sizeof( FMOD_CREATESOUNDEXINFO );
> info.useropen = MyOpen;
> info.userclose = MyClose;
> info.userread = MyRead;
> info.userseek = MySeek;
> system->createStream( (const char*)file, FMOD_DEFAULT, &info, &pTestSound1 );
> //here's the callback 
> FMOD_RESULT F_CALLBACK MyOpen( const char* name, int unicode, unsigned int *fileSize, void **handle, void** userData )
> {
> if ( name )
> {
> FILE* pFile = (FILE*)name;
> 
> fseek( pFile, 0, SEEK_END );
> *fileSize = ftell( pFile );
> fseek( pFile, 0, SEEK_SET );
> *handle = pFile;
> return FMOD_OK;
> }
> return FMOD_ERR_INVALID_PARAM;
> }
> 
> FMOD_RESULT F_CALLBACK MyClose( void* handle, void* userData )
> {
> if ( !handle )
> {
> return FMOD_ERR_INVALID_PARAM;
> }
> fclose( ( FILE* )handle );
> return FMOD_OK;
> }
> 
> FMOD_RESULT F_CALLBACK MyRead( void* handle, void* buffer, unsigned int sizebytes, unsigned int* bytesread, void* userData )
> {
> size_t haveRead = fread( buffer, 1, sizebytes, ( FILE* )handle );
> *bytesread = (unsigned int)haveRead;
> return FMOD_OK;
> }
> 
> FMOD_RESULT F_CALLBACK MySeek( void* handle, unsigned int pos, void* userData )
> {
> fseek( ( FILE* )handle, pos, SEEK_SET );
> return FMOD_OK;
> }
> ```
> 
> I switch to the 1.2.5 version recently and change void\*\*userData to void\*userData.  
> But Error Occurred!! Why? and how to fix it ?

Do you mean a compiler error? Have a look at FMOD\_CREATESOUNDEXINFO struct again, you can see your members are fileuseropen, fileuserseek, etc, rather than just useropen/userseek/…  
I do see that you probably saw that, if you changed void\*\*userdata to void \*userdata, which it is now.  
Did you pass 0 to createStream? That can return an error with your code.

I used your code and did this, and it played the sound no problem.

```auto

FMOD_RESULT F_CALLBACK MyOpen( const char* name, int unicode, unsigned int *fileSize, void** handle, void* userData )
{
   if ( name )
   {
      FILE* pFile = (FILE*)name;

      fseek( pFile, 0, SEEK_END );
      *fileSize = ftell( pFile );
      fseek( pFile, 0, SEEK_SET );
      *handle = pFile;
      return FMOD_OK;
   }
   return FMOD_ERR_INVALID_PARAM;
}

FMOD_RESULT F_CALLBACK MyClose( void* handle, void* userData )
{
   if ( !handle )
   {
      return FMOD_ERR_INVALID_PARAM;
   }
   fclose( ( FILE* )handle );
   return FMOD_OK;
}

FMOD_RESULT F_CALLBACK MyRead( void* handle, void* buffer, unsigned int sizebytes, unsigned int* bytesread, void* userData )
{
   size_t haveRead = fread( buffer, 1, sizebytes, ( FILE* )handle );
   *bytesread = (unsigned int)haveRead;
   return FMOD_OK;
}

FMOD_RESULT F_CALLBACK MySeek( void* handle, unsigned int pos, void* userData )
{
   fseek( ( FILE* )handle, pos, SEEK_SET );
   return FMOD_OK;
}

void main()
{
   FILE* file = NULL;
   FMOD::System *system;
   FMOD::Sound *pTestSound1;
   FMOD_RESULT result;
 
   result = FMOD::System_Create(&system);

   result = system->init(100, FMOD_INIT_NORMAL, 0);
 
   fopen_s( &file, "c:/media/waterfall.mp3", "rb" ); //read a file into the memory
 
   FMOD_CREATESOUNDEXINFO info;
   memset( &info, 0, sizeof( FMOD_CREATESOUNDEXINFO ) );
   info.cbsize = sizeof( FMOD_CREATESOUNDEXINFO );
   info.fileuseropen = MyOpen;
   info.fileuserclose = MyClose;
   info.fileuserread = MyRead;
   info.fileuserseek = MySeek;
   result = system->createStream( (const char*)file, FMOD_DEFAULT, &info, &pTestSound1 );
   result = result;

   system->playSound(pTestSound1, 0, false, 0);
   _getch();
    //here's the callback 
}
```

---

<div class="post-metadata">

**Author:** ![gdkid1412](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@gdkid1412](https://qa.fmod.com/u/gdkid1412)\
**Post date:** [November 12, 2013, 12:55am UTC](https://qa.fmod.com/t/error-occurred-when-using-fmod-file-opencallback/11198/4 "2013-11-12T00:55:55Z")

</div>

Thanks for your reply.  
That problem has been solved.I checked FMOD\_CREATESOUNDEXINFO again,but the members are still useropen/userseek/… Maybe I used a old version.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [November 12, 2013, 2:20am UTC](https://qa.fmod.com/t/error-occurred-when-using-fmod-file-opencallback/11198/5 "2013-11-12T02:20:33Z")

</div>

sorry, the members are still called useropen/userseek etc, I am referring to 1.03.00 which is coming out soon.
