2011-02-24 6 views
0

WaveOutGetDevCaps를 사용하여 시스템의 오디오 장치 이름을 가져 오는 이전 코드 기반을 유지 관리하고 있습니다. WAVEOUTCAPS.szPname은 MAXPNAMELEN (31 문자)에 의해 제한되므로 Windows 7 시스템에서는 이름이 잘립니다.waveOutGetDevCaps, Win7 및 긴 장치 이름

이 작업을 수행하는 Win7의 방법은 무엇입니까?

답변

0

당신은 코어 오디오 API 중 하나를 사용할 수 있습니다

// get the device enumerator 
IMMDeviceEnumerator* pEnumerator = NULL; 
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, 
           CLSCTX_ALL,__uuidof(IMMDeviceEnumerator), 
           (void**)&pEnumerator); 

// get the endpoint collection 
IMMDeviceCollection* pCollection = NULL; 
DWORD mask = DEVICE_STATE_ACTIVE || DEVICE_STATE_UNPLUGGED; 
hr = pEnumerator->EnumAudioEndpoints(eRender, mask, &pCollection); 

// get the size of the collection 
UINT count = 0; 
hr = pCollection->GetCount(&count); 

for (int i = 0; i < (int)count; i++) 
{ 
    // get the endpoint 
    IMMDevice* pEndPoint = NULL; 
    hr = pCollection->Item(i, &pEndPoint); 

    // get the human readable name 
    String^ friendlyName; 
    IPropertyStore* pProps = NULL; 
    HRESULT hr = pEndPoint->OpenPropertyStore(STGM_READ, &pProps); 
    PROPVARIANT varName; 
    PropVariantInit(&varName); 
    hr = pProps->GetValue(PKEY_Device_FriendlyName, &varName); 
    friendlyName = gcnew String(varName.pwszVal); 
    PropVariantClear(&varName); 
}  

오류 처리는 위의 코드에서 제거가 더 읽기 쉽게 만들 수 있습니다. (C#과 Windows API 사이를 이동하기 위해 C++/CLI를 사용하는 것을 좋아합니다.)

이제는 더 오래된 부분이 이전 코드베이스의 MME 장치와 관련됩니다.