From 7cf872ec6f7e836f127061cdc4b2204d6872ac6a Mon Sep 17 00:00:00 2001 From: Hane Date: Wed, 25 Jan 2023 18:11:25 +0100 Subject: [PATCH] perito bro --- README.md | 82 +++++++++++++++++++ testmain.cpp | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 309 insertions(+) create mode 100644 README.md create mode 100644 testmain.cpp diff --git a/README.md b/README.md new file mode 100644 index 0000000..9e93252 --- /dev/null +++ b/README.md @@ -0,0 +1,82 @@ +enberda filipas con esta mierda, eh. Increible que esto lo haya hecho alguien digno de ser big techie. + +Anyway, al caso: + + +IMMDeviceEnumerator +| +| +| +| +| +IMMDeviceCollection +| +| +| +| +| +IMMDevice--------------------------------------| +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +| \ | +IMMEndpoint IAudioEndpointVolume IAudioSessionManager2 +(No demostrado) (Columen endpoint) (Manager de sesiones) + | + | + | + | + | + | + | + | + | + | + | + | + | + IAudioSessionEnumerator + (Handle de sesiones) + | + | + | + | + | + | + | + | + | + | + | + | + | + IAudioSessionControl2 + (Cast a padre, 1 x sesion) + | + | + | + | + | + | + | + | + | + | + | + | + | + ISimpleAudioVolume + (Via QueryInterface(), 1 x sesion ofc) + + +Ezpz microsoft comeme los cojones \ No newline at end of file diff --git a/testmain.cpp b/testmain.cpp new file mode 100644 index 0000000..ea700e1 --- /dev/null +++ b/testmain.cpp @@ -0,0 +1,227 @@ +#define WIN32_LEAN_AND_MEAN + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +//#include +//#include +#include + + +//#define EXIT_ON_ERROR(hres, className) \ + if (FAILED(hres)) { printf("%s\n", #className); goto Exit; } + + +#define EXIT_ON_ERROR(hres) \ + if (FAILED(hres)) { printf("%s - %d\n", __FILE__, __LINE__); goto Exit; } + + +#define SAFE_RELEASE(punk) \ + if ((punk) != NULL) \ + { (punk)->Release(); (punk) = NULL; } + +//#pragma once + +/* + * Comentarios patrocinados por David + * Enviar mensaje a @Phireh + */ + +// const IID IntID_IAudioEndpointVolume = __uuidof(IAudioEndpointVolume); + +IMMDeviceEnumerator *deviceEnumeratorPtr = NULL; +IMMDeviceCollection *deviceCollectionPtr = NULL; +IMMDevice *endpointPtr = NULL; + +IAudioEndpointVolume *endpointVolumePtr = NULL; +IAudioSessionManager2 *sessionManagerPtr = NULL; + +IAudioSessionEnumerator *sessionEnumeratorPtr = NULL; +IAudioSessionControl2 *sessionControl2Ptr = NULL; +ISimpleAudioVolume *sessionVolumePtr = NULL; + +void PrintEndpointNames() { + + HRESULT hr = S_OK; + IPropertyStore *deviceEndpointPropertiesPtr = NULL; + LPWSTR endpointID = NULL; + + hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + EXIT_ON_ERROR(hr) + + //MMDeviceEnumerator es el CLSID de toda la vaina de MMDevicear + hr = CoCreateInstance( + __uuidof(MMDeviceEnumerator), NULL, + CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), + (void**)&deviceEnumeratorPtr); + EXIT_ON_ERROR(hr) + + //hr = deviceEnumeratorPtr->EnumAudioEndpoints(eRender, DEVICE_STATE_&deviceCollectionPtr); + //Llamar a dispositivo por defecto. 2o param no importa lmao + hr = deviceEnumeratorPtr->GetDefaultAudioEndpoint(eRender, eConsole, &endpointPtr); + EXIT_ON_ERROR(hr) + + // UINT count; + // hr = deviceCollectionPtr->GetCount(&count); + // EXIT_ON_ERROR(hr) + + // if (count == 0) { + // printf("No endpoints found.\n"); + // } + + // hr = deviceCollectionPtr->Item(i, &endpointPtr); + // EXIT_ON_ERROR(hr) + + //RECUPERAR ENDPOINT ID + hr = endpointPtr->GetId(&endpointID); + EXIT_ON_ERROR(hr) + + //RECUPERAR STRUCT DE PROPIEDADES + hr = endpointPtr->OpenPropertyStore(STGM_READ, &deviceEndpointPropertiesPtr); + EXIT_ON_ERROR(hr) + + + PROPVARIANT varName; + // Initialize container for property value. + PropVariantInit(&varName); + + // Get the endpoint's friendly-name property. + hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName); + EXIT_ON_ERROR(hr) + + //PINTAR ID + PROPIEDAD RECUPERADA + printf("Endpoint %d: \"%S\" (%S)\n", 0, varName.pwszVal, endpointID); + + + //Activamos desde Device para tener control sobre el Endpoint + hr = endpointPtr->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&endpointVolumePtr); + EXIT_ON_ERROR(hr) + + hr = endpointVolumePtr->SetMasterVolumeLevelScalar(0.4f, NULL); + EXIT_ON_ERROR(hr); + + //Registramos el gestor de sesiones para conseguir el handle que da el handle de sesiones a nivel informativo + //Y justo despues, el que da control a nivel sonoro xdddddddddddddddddddddddddddddddddddddddddddddd + hr = endpointPtr->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**) &sessionManagerPtr); + EXIT_ON_ERROR(hr); + + + //Ahora si viene el handle de las sesiones xdddddddddd + hr = sessionManagerPtr->GetSessionEnumerator(&sessionEnumeratorPtr); + EXIT_ON_ERROR(hr); + + //Cogemos el numero de sesiones y recorremos para coger cada una + //Luego tho, que soy una puta vaga y hay que probar cositas + INT sessionCount; + hr = sessionEnumeratorPtr->GetCount(&sessionCount); + EXIT_ON_ERROR(hr); + + hr = sessionEnumeratorPtr->GetSession(2, (IAudioSessionControl**)&sessionControl2Ptr); + EXIT_ON_ERROR(hr); + + LPWSTR sessionDisplayName; + hr = sessionControl2Ptr->GetDisplayName(&sessionDisplayName); + EXIT_ON_ERROR(hr); + + + printf("Sesion 0 de endpoint %S: \"%S\" \n Num sesiones: (%d)\n", varName.pwszVal, sessionDisplayName, sessionCount); + + //hr = sessionControlPtr->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&sessionControl2Ptr); + //EXIT_ON_ERROR(hr); + + //hr = sessionControl2Ptr->GetProcessId(&foundProcessId); + //EXIT_ON_ERROR(hr); + + hr = sessionControl2Ptr->QueryInterface(__uuidof(ISimpleAudioVolume), (void**)&sessionVolumePtr); + EXIT_ON_ERROR(hr); + + hr = sessionVolumePtr->SetMute(TRUE, 0); + EXIT_ON_ERROR(hr); + + //Limpiamos memoria + CoTaskMemFree(endpointID); + endpointID = NULL; + PropVariantClear(&varName); + SAFE_RELEASE(deviceEndpointPropertiesPtr) + SAFE_RELEASE(endpointPtr) + SAFE_RELEASE(endpointVolumePtr); + SAFE_RELEASE(sessionManagerPtr); + SAFE_RELEASE(sessionEnumeratorPtr); + SAFE_RELEASE(sessionControlPtr); + SAFE_RELEASE(sessionControl2Ptr); + SAFE_RELEASE(sessionVolumePtr); +/* + // Each loop prints the name of an endpoint device. + for (ULONG i = 0; i < count; i++) { + // Get pointer to endpoint number i. + hr = deviceCollectionPtr->Item(i, &endpointPtr); + EXIT_ON_ERROR(hr) + + // Get the endpoint ID string. + hr = endpointPtr->GetId(&endpointID); + EXIT_ON_ERROR(hr) + + hr = endpointPtr->OpenPropertyStore(STGM_READ, &deviceEndpointPropertiesPtr); + EXIT_ON_ERROR(hr) + + PROPVARIANT varName; + // Initialize container for property value. + PropVariantInit(&varName); + + // Get the endpoint's friendly-name property.2 + hr = deviceEndpointPropertiesPtr->GetValue(PKEY_Device_FriendlyName , &varName); + EXIT_ON_ERROR(hr) + + // Print endpoint friendly name and endpoint ID. + printf("Endpoint %lu: \"%S\" (%S)\n", i, varName.pwszVal, endpointID); + + + + + + CoTaskMemFree(endpointID); + endpointID = NULL; + PropVariantClear(&varName); + SAFE_RELEASE(deviceEndpointPropertiesPtr) + SAFE_RELEASE(endpointPtr) + } +*/ + SAFE_RELEASE(deviceEnumeratorPtr) + SAFE_RELEASE(deviceCollectionPtr) + return; + +Exit: + printf("Error!\n"); + CoTaskMemFree(endpointID); + SAFE_RELEASE(deviceEnumeratorPtr) + SAFE_RELEASE(deviceCollectionPtr) + SAFE_RELEASE(endpointPtr) + SAFE_RELEASE(deviceEndpointPropertiesPtr) + CoUninitialize(); +} + +void onExit(){ + + + + + +} + + + +int main (int argc, char* argv[]) { + PrintEndpointNames(); +}