Last active
July 12, 2022 18:48
-
-
Save rdp/8363580 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // compile (mingw-w64) | |
| // g++ this_filename.c -luuid -loleaut32 -lole32 | |
| #include <windows.h> | |
| #include <commctrl.h> | |
| #include <mmdeviceapi.h> | |
| #include <endpointvolume.h> | |
| #include <stdio.h> | |
| // mostly gleaned via "copy and paste" from http://msdn.microsoft.com/en-us/library/windows/desktop/dd370839(v=vs.85).aspx | |
| #define EXIT_ON_ERROR(hr) \ | |
| if (FAILED(hr)) { goto Exit; } | |
| #define SAFE_RELEASE(punk) \ | |
| if ((punk) != NULL) \ | |
| { (punk)->Release(); (punk) = NULL; } | |
| int main(int argc, char** args) { | |
| IAudioEndpointVolume *g_pEndptVol = NULL; | |
| bool WindowsLH; | |
| HRESULT hr = S_OK; | |
| IMMDeviceEnumerator *pEnumerator = NULL; | |
| IMMDevice *pDevice = NULL; | |
| OSVERSIONINFO VersionInfo; | |
| ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFO)); | |
| VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | |
| GetVersionEx(&VersionInfo); | |
| if (VersionInfo.dwMajorVersion > 5) | |
| WindowsLH = true; // vista+ | |
| else | |
| WindowsLH = false; | |
| if (WindowsLH) | |
| { | |
| CoInitialize(NULL); | |
| // Get enumerator for audio endpoint devices. | |
| hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), | |
| NULL, CLSCTX_INPROC_SERVER, | |
| __uuidof(IMMDeviceEnumerator), | |
| (void**)&pEnumerator); | |
| EXIT_ON_ERROR(hr) | |
| // Get default audio-rendering device. | |
| hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice); | |
| EXIT_ON_ERROR(hr) | |
| hr = pDevice->Activate(__uuidof(IAudioEndpointVolume), | |
| CLSCTX_ALL, NULL, (void**)&g_pEndptVol); | |
| EXIT_ON_ERROR(hr) | |
| float pfLevelMinDB; | |
| float pfLevelMaxDB; | |
| float pfVolumeIncrementDB; | |
| hr = g_pEndptVol->GetVolumeRange(&pfLevelMinDB, &pfLevelMaxDB, &pfVolumeIncrementDB); | |
| EXIT_ON_ERROR(hr) | |
| float currentVal; | |
| hr = g_pEndptVol->GetMasterVolumeLevel(¤tVal); | |
| EXIT_ON_ERROR(hr) | |
| printf("current master volume is %f (min %f max %f inc %f)", currentVal, pfLevelMinDB, pfLevelMaxDB, pfVolumeIncrementDB); | |
| } | |
| else { | |
| printf("wrong v of windows, req. vista+\n"); | |
| } | |
| Exit: | |
| SAFE_RELEASE(pEnumerator) | |
| SAFE_RELEASE(pDevice) | |
| SAFE_RELEASE(g_pEndptVol) | |
| CoUninitialize(); | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note to self, how to compile it: g++ -IC:\downloads\i686-4.8.2-release-posix-sjlj-rt_v3-rev2\mingw32\i686-w64-mingw32\include go.c -lole32