次の方法で共有


ISpMMSysAudio::GetDeviceId (SAPI 5.3)

Microsoft Speech API 5.3

ISpMMSysAudio::GetDeviceId

ISpMMSysAudio::GetDeviceId passes back the multimedia device ID being used by the audio object.

  
    HRESULT GetDeviceId(
   UINT  *puDeviceId
);

Parameters

  • puDeviceId
    [out] Pointer receiving the device ID.

Return values

Value
S_OK
E_POINTER

Remarks

The default device ID for SpMMSysAudio objects that are created using CoCreateInstance is the WAVE_MAPPER. For audio objects created using an object token, the ID will always be a specific wave in or wave out device ID.

Example

The following code snippet illustrates the use of ISpMMSysAudio::GetDeviceId using CoCreateInstance.

  
// Declare local identifiers:
HRESULT                   hr = S_OK;
CComPtr<ISpMMSysAudio>    cpMMSysAudio;
UINT                      uiDeviceId;
	
// Create the multimedia input object.
hr = cpMMSysAudio.CoCreateInstance(CLSID_SpMMAudioIn);

if (SUCCEEDED(hr))
{
   // Get the default device Id (that
   // is, uiDeviceId == WAVE_MAPPER).
   hr = cpMMSysAudio->GetDeviceId(&uiDeviceId;);
}

if (SUCCEEDED(hr))
{
   // Do something here.
}

The following code snippet illustrates the use of ISpMMSysAudio::GetDeviceId using an ISpObjectToken

  
// Declare local identifiers:
HRESULT                       hr = S_OK;
CComPtr<ISpMMSysAudio>        cpMMSysAudio;
CComPtr<ISpObjectWithToken>   cpObjectWithToken;
CComPtr<ISpObjectToken>       cpObjectToken;
UINT                          uiDeviceId;
	
// Create the multimedia input object.
hr = cpMMSysAudio.CoCreateInstance(CLSID_SpMMAudioIn);

if (SUCCEEDED(hr))
{
   // Get the current multimedia object's object token.
   hr = cpMMSysAudio.QueryInterface(&cpObjectWithToken;);
}

if (SUCCEEDED(hr))
{
   // Find the preferred multimedia object token.
   hr = SpFindBestToken(SPCAT_AUDIOIN, L"Technology=MMSys", NULL, &cpObjectToken;);
}

if (SUCCEEDED(hr))
{
   // Set the current multimedia object to the preferred multimedia object token.
   hr = cpObjectWithToken->SetObjectToken(cpObjectToken);
}

if (SUCCEEDED(hr))
{
   // Get the device id for the object (that
   // is, uiDeviceId != WAVE_MAPPER).
   hr = cpMMSysAudio->GetDeviceId(&uiDeviceId;);
}

if (SUCCEEDED(hr))
{
   // Do stuff here.
}