-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetVolume.h
More file actions
40 lines (30 loc) · 1 KB
/
GetVolume.h
File metadata and controls
40 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <Windows.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
int GetVolume()
{
HRESULT hr = NULL;
bool decibels = false;
bool scalar = false;
//double newVolume = nVolume;
CoInitialize(NULL);
IMMDeviceEnumerator *deviceEnumerator = NULL;
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER,
__uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
IMMDevice *defaultDevice = NULL;
hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
deviceEnumerator->Release();
deviceEnumerator = NULL;
IAudioEndpointVolume *endpointVolume = NULL;
hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume),
CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
defaultDevice->Release();
defaultDevice = NULL;
// -------------------------
float currentVolume = 0;
endpointVolume->GetMasterVolumeLevelScalar(¤tVolume);
endpointVolume->Release();
CoUninitialize();
return static_cast<int> (currentVolume * 100);
}