How to make XAudio2 throw a Device Lost flag/error?

Derek Todd 0 Reputation points
2024-10-01T02:15:50.39+00:00

Hi,

I was wondering how I can produce a Device Lost message for XAudio2. I tried using the dxcaps -forcetdr command in the Developer Command Prompt window for Visual Studio, but it did not work. I am using C++ and programming for Windows 10.

Derek

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,651 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,758 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Xu - MSFT 2,471 Reputation points Microsoft Vendor
    2024-10-01T09:14:14.06+00:00
    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";
    
    
    

    You just need to use XAudioCreate to match XAUDIO2_E_DEVICE_INVALIDATED.

    Don't forget Initializing it before using it:
    CoInitializeEx(NULL, COINIT_MULTITHREADED);

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.