#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(); }