Airforcex6
-
Posts
4 -
Joined
-
Last visited
Posts posted by Airforcex6
-
-
Hi!
I have a simple problem which I couldn't solve. It is about changing master sound level in Windows Vista / Windows 7 using the application compiled with Visual Studio 2010. There is the code given below which I have used in order to adjust master volume level, but nothing have happened. Can anyone point out to me the mistake inside the source code?
Thank you in advance!
CODE
#include <mmdeviceapi.h>
#include <endpointvolume.h>
#include <windows.h>
#include <tchar.h>
#pragma comment(lib, "winmm.lib");
int _tmain(int argc, _TCHAR* argv[])
{
double nVolume = 0.1; // Mute is 0 and full blast is 1.0
bool ChangeVolume((double) nVolume);
}
bool ChangeVolume(double nVolume,bool bScalar)
{
bScalar = true;
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->GetMasterVolumeLevel(¤tVolume);
//printf("Current volume in dB is: %f\n", currentVolume);
hr = endpointVolume->GetMasterVolumeLevelScalar(¤tVolume);
//CString strCur=L"";
//strCur.Format(L"%f",currentVolume);
//AfxMessageBox(strCur);
// printf("Current volume as a scalar is: %f\n", currentVolume);
if (bScalar==false)
{
hr = endpointVolume->SetMasterVolumeLevel((float)newVolume, NULL);
}
else if (bScalar==true)
{
hr = endpointVolume->SetMasterVolumeLevelScalar((float)newVolume, NULL);
}
endpointVolume->Release();
CoUninitialize();
return FALSE;
}
-
Hi guys again!
If you sometime read the text above which I wrote , I just wish to say that I managed to compile the source code which as a header file uses the "functions.h". The trick was to use Visual C++ instead of DEV C++.
Anyway, tanks, you helped me!
Regards!
-
Hi guys!
I've red your discussion about possibility of changing system sound using the programs which you have written, but when I tried to compile it on my computer, or to download them from the links you had been posted, some problems rose up.
Can anyone help me? I have the similar problem like Fishmonger had. :)
Regards!
Master Sound Level Windows Vista/7
in Questions
Posted
Thank you anyway, I have found the code that works well!
Here it is:
CODE
#include <WinSDKVer.h>
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#include <SDKDDKVer.h>
#define WIN32_LEAN_AND_MEAN
// Windows Header Files:
#include <windows.h>
#include <tchar.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//double newVolume = _ttof(lpCmdLine);
double newVolume = 0.1; // Put the value between 0.0 and 1.0
CoInitialize(NULL);
IMMDeviceEnumerator* deviceEnumerator = NULL;
if(CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator) == S_OK) {
IMMDevice* defaultDevice = NULL;
if(deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice) == S_OK) {
IAudioEndpointVolume* endpointVolume = NULL;
if(defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume) == S_OK) {
endpointVolume->SetMasterVolumeLevelScalar((float)newVolume, NULL);
endpointVolume->Release();
}
defaultDevice->Release();
}
deviceEnumerator->Release();
}
CoUninitialize();
return 0;
}