locked
How to fix the problem about DeviceInformation::FindAllAsync(DeviceClass) ? RRS feed

  • Question

  • Hi,<o:p></o:p>

    My computer has two audio drivers. One is High Definition Audio,and another is NVidia High Definition Audio.<o:p></o:p>

    The Device Manger is like this .

        High Definition Audio.

        NVIDA High Definition Audio.

    When I use DeviceInformation::FindAllAsync(DeviceClass)  like this code block.

          

     DeviceClass dataFlow;
     if ( SPEECH_MODE_PLAYBACK == nMode )
     {
      dataFlow = DeviceClass::AudioRender;
     }
     else
     {
      dataFlow = DeviceClass::AudioCapture;
     }

       auto findAllOp = DeviceInformation::FindAllAsync( dataFlow );
     HANDLE hTmp = CreateEventExW( NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE );
     for ( ;; )
     {
      if ( Windows::Foundation::AsyncStatus::Completed == findAllOp->Status )
      {
       break;
      }
      WaitForSingleObjectEx( hTmp, 100, FALSE );
     }
     CloseHandle( hTmp );

     auto findOp = findAllOp->GetResults();
     unsigned int nDevices =  findOp->Size;

     if ( nDevices < 1 )
     {
      DebugPrint( _T("[Error][Initialize]: No Available Device!\n") );
      return -1;
     }

    When the  dataFlow equal  DeviceClass::AudioRender,I get the a value 1 for nDevice.Because I have only one   headphones.But when I  disable the NVIDA High Definition Audio ,I get the value is 0.So my program will crash in the next statement. However, I comment out  this if branch.My program will run well. Because I can still get the default device.Of course,I do not use the FindAllAsync method. 

        So I suspect that this method(FindAllAsync)  has a problem.

     

    Thursday, July 11, 2013 2:13 AM

Answers

  • Hi GeneralHuang,

    Your app should be able to handle error results without crashing. It should check that the result was valid before dereferencing it.

    From the values you report, it sounds like only the NVIDIA High Definition Audio device is showing up as the AudioRender device. This is consistent between your two cases.

    --Rob

    Friday, July 12, 2013 2:09 AM
    Moderator

All replies

  • Hi GeneralHuang,

    Your app should be able to handle error results without crashing. It should check that the result was valid before dereferencing it.

    From the values you report, it sounds like only the NVIDIA High Definition Audio device is showing up as the AudioRender device. This is consistent between your two cases.

    --Rob

    Friday, July 12, 2013 2:09 AM
    Moderator
  • Hi,thank you very much.Please leave me your email and  there are some details I want to  decrible.
    Monday, July 15, 2013 2:15 AM