CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2015
    Posts
    7

    Enumerate Audio Devices

    I'm trying to get some information from audio devices however whenever I run my code below, the device description and manufacturer are wrong. What am I doing wrong?

    Code:
    #include <stdio.h>
    #include <SetupAPI.h>
    #include <devpkey.h>
    
    DWORD STDAPICALLTYPE EnumAudioDevices() {
    
    	HANDLE hEnumerator = NULL;
    	DWORD dwIndex = 0;
    	WCHAR szBuffer[256] = { 0 };
    	DEVPROPTYPE propType = 0;
    	SP_DEVINFO_DATA spDeviceInfo = { sizeof(SP_DEVINFO_DATA) };
    
    	hEnumerator = SetupDiGetClassDevs(NULL, L"SWD\\MMDEVAPI", NULL, DIGCF_ALLCLASSES);
    
    	while (SetupDiEnumDeviceInfo(hEnumerator, dwIndex++, &spDeviceInfo)) {
    
    		// Name
    		SetupDiGetDeviceProperty(hEnumerator, &spDeviceInfo, &DEVPKEY_Device_FriendlyName, &propType, (PBYTE)szBuffer, 512, NULL, 0);
    		wprintf(L"\nDevice %i: %s\n", dwIndex, szBuffer);
    		memset(szBuffer, 0, 512);
    
    		// ID
    		SetupDiGetDeviceInstanceId(hEnumerator, &spDeviceInfo, szBuffer, 512, NULL);
    		wprintf(L"ID: %s\n", szBuffer);
    		memset(szBuffer, 0, 512);
    
    		// Description
    		SetupDiGetDeviceProperty(hEnumerator, &spDeviceInfo, &DEVPKEY_Device_DeviceDesc, &propType, (PBYTE)szBuffer, 512, NULL, 0);
    		wprintf(L"Description: %s\n", szBuffer);
    		memset(szBuffer, 0, 512);
    
    		// Manufacturer
    		SetupDiGetDeviceProperty(hEnumerator, &spDeviceInfo, &DEVPKEY_Device_Manufacturer, &propType, (PBYTE)szBuffer, 512, NULL, 0);
    		wprintf(L"Manufacturer: %s\n", szBuffer);
    		memset(szBuffer, 0, 512);
    
    	}
    
    	return dwIndex;
    }
    
    int __cdecl main() {
    
    	wprintf(L"\nDevice Count: %i\n\n", EnumAudioDevices());
    
    	return 0;
    }

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Enumerate Audio Devices

    don't know the specifics of that API call, but it's similar to many others so...
    you may need to set the sizeof the devinfo data explicitely on each call rather than just once
    you may need to set the rest of the buffer to zero explicitely on each call rather than just once

  3. #3
    Join Date
    Aug 2015
    Posts
    7

    Re: Enumerate Audio Devices

    The info gets put into the buffer correctly but it does match what is in the Sound section of the control panel. For example: instead of saying "Realtek" for device manufacturer it says "Microsoft".

    Edit: I think I figured out why this is happening. Windows treats Audio Devices and Audio Device Endpoints as totally different devices (even though they arent). I can obtain what seems to be a symbolic link to the underlying device (it's the underlying device ID) but how can I get some properties from this?

    The value is: HDAUDIO\FUNC_01&VEN_10EC&DEV_0288&SUBSYS_10EC0191&REV_1000\4&3a2ab354&0&0001
    Last edited by cmajor28; August 3rd, 2015 at 07:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured