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
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.
Ok got it... I forgot the CoInitializeEx(NULL, COINIT_MULTITHREADED);
before the code. Now it returns S_OK
!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.