0

When I try to use XAudio2 it already fails at the XAudio2Create(...) function. (INITIALIZE returns at this line: if (FAILED(hr)) return false; I don't know why and google only tells me to install the directx redistributable, which I did but nothing changed... Any Ideas?

This is basicly code from MSDN:

IXAudio2* pXAudio2 = NULL;

bool INITIALIZE()
{
    HRESULT hr = XAudio2Create(&pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR);
    if (FAILED(hr)) return false;
    .
    .
    .
}

I tried this but none of those Error-Codes seem to match:

HRESULT hr = XAudio2Create(&pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR);
std::cout << "hresult: " << hr << std::endl;
if (hr == XAUDIO2_E_DEVICE_INVALIDATED) std::cout << "XAUDIO2_E_DEVICE_INVALIDATED";
if (hr == XAUDIO2_E_INVALID_CALL) std::cout << "XAUDIO2_E_INVALID_CALL";
if (hr == XAUDIO2_E_XAPO_CREATION_FAILED) std::cout << "XAUDIO2_E_XAPO_CREATION_FAILED";
if (hr == XAUDIO2_E_XMA_DECODER_ERROR) std::cout << "XAUDIO2_E_XMA_DECODER_ERROR";
if (hr == S_OK) std::cout << "S_OK";

Output:

hresult: -2147221008
theCNG27
  • 405
  • 8
  • 27

2 Answers2

0

Never mind Google: use the documentation:

Returns S_OK if successful, an error code otherwise. See XAudio2 Error Codes for descriptions of XAudio2 specific error codes.

Simply check that error code to find out what's going on.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • But my HRESULT is not equal to any of those Error Codes... (see edited question). Does it make a difference whether I use the `XAudio2.h` from DirectX SDK June 2010 or the `xaudio2.h` from Windows8 SDK!? (Im running Windows7) – theCNG27 Jan 10 '14 at 03:06
0

Ok got it... I forgot the CoInitializeEx(NULL, COINIT_MULTITHREADED); before the code. Now it returns S_OK!

theCNG27
  • 405
  • 8
  • 27