Jump to content
  • Advertisement
Sign in to follow this  
1st_maza

IXAudio2* audio

This topic is 3438 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How come this doesnt work? winmain: --- IXAudio2* audio = 0; releaseAudio( &audio ); --- void releaseAudio( IXAudio2* audio ) { if( audio ) { audio->Release(); audio = 0; } } Its 3am here, what am I missing?

Share this post


Link to post
Share on other sites
Advertisement
By "doesn't work", I'm assuming you get compile errors. The reason is in your WinMain, you're trying to pass a pointer to a pointer to an IXAudio2. Presumably, you want something like:


void releaseAudio(IXAudio2 *&audio)
{
if (audio)
{
audio->Release();
audio = 0;
}
}

....

IXAudio2 *audio = 0;
releaseAudio(audio);

Share this post


Link to post
Share on other sites
You could also use a pointer to a pointer in order to use it like his origenal method showed. Personaly I prefer doing it this way since its clearer looking at the code that it may change the pointer since your passing a pointer to it.

void releaseAudio(IXAudio2** audio)
{
if(*audio)
{
(**audio).Release();
*audio = NULL;//set the pointer that we are pointing to to null
}
}

...
IXAudio2 *audio = pointer to audio object...
releaseAudio(&audio);
//audio is now realeased and set to null


Share this post


Link to post
Share on other sites
Or even simpler:
void releaseAudio( IXAudio2 *& audio )
{
if (audio)
{
audio->Release();
audio = 0;
}
}

IXAudio2 * audio = ...;
releaseAudio( audio );

Share this post


Link to post
Share on other sites
And that is diffrent from the second post how exactly, cause I just looked at both 3 times and they both seem to be passing a refrence to a pointer.

Share this post


Link to post
Share on other sites
Both have the same effect but the *& version has the disadvantage that it is less obvious that the releaseAudio function takes its parameters by reference and not by value. Thus making it hard to grasp at the first glance what happens when you look at the code. ;)

Share this post


Link to post
Share on other sites
Sorry about that, it was late:

audio.h(9) : error C2061: syntax error : identifier 'IXAudio2'
audio.h(11) : error C2065: 'IXAudio2' : undeclared identifier
audio.h(11) : error C2065: 'audio' : undeclared identifier

edit:
eh, im still getting the same errors..

---winmain, main.cpp---
IXAudio2* audio = 0;
releaseAudio( audio );
---audio.cpp---
void releaseAudio( IXAudio2 *& audio )
{
if( audio )
{
audio->Release();
audio = 0;
}
}
---audio.h
void releaseAudio( IXAudio2 *& audio );

Share this post


Link to post
Share on other sites
Quote:
Original post by 1st_maza
audio.h(9) : error C2061: syntax error : identifier 'IXAudio2'
audio.h(11) : error C2065: 'IXAudio2' : undeclared identifier
audio.h(11) : error C2065: 'audio' : undeclared identifier
Looks like you didn't #include <XAudio2.h>

By the way, the reason I chose the reference-to-pointer is so that the "releaseAudio" function looks like those "SAFE_RELEASE" macros that people tend to write (which is what I assumed this function was supposed to be a replacement for). Personally, I think writing the Release() logic out manually is clearer anyway (and you don't typically write it like that often either), but that's just personal preference.

Share this post


Link to post
Share on other sites
"By the way, the reason I chose the reference-to-pointer is so that the "releaseAudio" function looks like those "SAFE_RELEASE" macros that people tend to write (which is what I assumed this function was supposed to be a replacement for). Personally, I think writing the Release() logic out manually is clearer anyway (and you don't typically write it like that often either), but that's just personal preference."

Well, I havent mastered all the correct ways of writing code, but im learning.

edit:
fatal error C1083: Cannot open include file: 'XAudio2.h': No such file or directory
This isnt included in SDK or when Visual is installed?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!