Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 871263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:36:54+00:00 2026-05-15T10:36:54+00:00

I made a program to mute microphone using WinAPI and it seems to work

  • 0

I made a program to mute microphone using WinAPI and it seems to work perfectly in Windows XP but doesn’t do a thing in Windows 7. Is it possible to control microphone volume or mute with WinAPI in Windows 7?

void setVolume(DWORD volume) {
HMIXER mixer;

if (mixerOpen(&mixer, 0, 0, 0, 0) != MMSYSERR_NOERROR) {
    MessageBoxW(NULL, L"Error: mixerOpen()", NULL, MB_ICONHAND);
    return;
}

// Get the line info
MIXERCAPS mixcaps;
MIXERLINE mixerLine;
mixerGetDevCaps(0, &mixcaps, sizeof(MIXERCAPS));
mixerLine.cbStruct = sizeof(MIXERLINE);
mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mixerLine.dwSource = 0;
mixerLine.dwDestination = 0;

if (mixerGetLineInfo(reinterpret_cast<HMIXEROBJ>(mixer), &mixerLine, MIXER_GETLINEINFOF_SOURCE)
    != MMSYSERR_NOERROR) {
        MessageBoxW(NULL, L"Error: mixerGetLineInfo()", NULL, MB_ICONHAND);
        return;
}

// Get control for mixerline
MIXERCONTROL mixerCtrl;
MIXERLINECONTROLS mixerLineCtrl;

mixerLineCtrl.cbStruct = sizeof(MIXERLINECONTROLS);
mixerLineCtrl.dwLineID = mixerLine.dwLineID;
mixerLineCtrl.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mixerLineCtrl.cControls = 1;
mixerLineCtrl.pamxctrl = &mixerCtrl;
mixerLineCtrl.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineCtrl.cControls = 5;

if (mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(mixer), &mixerLineCtrl, MIXER_GETLINECONTROLSF_ONEBYTYPE)
    != MMSYSERR_NOERROR) {
        MessageBoxW(NULL, L"Error: mixerGetLineControls()", NULL, MB_ICONHAND);
        return;
}

// Volume..
MIXERCONTROLDETAILS mixerCtrlDetails;
MIXERCONTROLDETAILS_UNSIGNED mixerCtrlDetailsUnsigned;

mixerCtrlDetailsUnsigned.dwValue = volume;
mixerCtrlDetails.dwControlID = mixerCtrl.dwControlID;
mixerCtrlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
mixerCtrlDetails.cMultipleItems = 0;
mixerCtrlDetails.paDetails = &mixerCtrlDetailsUnsigned;
mixerCtrlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mixerCtrlDetails.cChannels = 1;

if (mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(mixer), &mixerCtrlDetails, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE)
    != MMSYSERR_NOERROR) {
        MessageBoxW(NULL, L"Error: mixerSetControlDetails()", NULL, MB_ICONHAND);
        return;
}

mixerClose(mixer);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:36:55+00:00Added an answer on May 15, 2026 at 10:36 am

    You need to use the new audio APIs introduced by Windows Vista.

    Here is an example.

    *EDIT: Visual Studio 2015 (C++):

    Usange:

    // To 100%
    ConsoleApplication3.exe -f 1
    
    // To  0%
    ConsoleApplication3.exe -f 0
    
    // To 50%
    ConsoleApplication3.exe -f 0.50
    

    Code:

    enter image description here

    #include "stdafx.h"
    #include <stdio.h>
    #include <windows.h>
    #include <mmdeviceapi.h>
    #include <endpointvolume.h>
    
    void Usage()
    {
        printf("Usage: \n");
        printf(" SetVolume [Reports the current volume]\n");
        printf(" SetVolume -d <new volume in decibels> [Sets the current default render device volume to the new volume]\n");
        printf(" SetVolume -f <new volume as an amplitude scalar> [Sets the current default render device volume to the new volume]\n");
    
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
        HRESULT hr;
        bool decibels = false;
        bool scalar = false;
        double newVolume;
        if (argc != 3 && argc != 1)
        {
            Usage();
            return -1;
        }
        if (argc == 3)
        {
            if (argv[1][0] == '-')
            {
                if (argv[1][1] == 'f')
                {
                    scalar = true;
                }
                else if (argv[1][1] == 'd')
                {
                    decibels = true;
                }
            }
            else
            {
                Usage();
                return -1;
            }
    
            newVolume = _tstof(argv[2]);
        }
    
        // -------------------------
        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(&currentVolume);
        printf("Current volume in dB is: %f\n", currentVolume);
    
        hr = endpointVolume->GetMasterVolumeLevelScalar(&currentVolume);
        printf("Current volume as a scalar is: %f\n", currentVolume);
        if (decibels)
        {
            hr = endpointVolume->SetMasterVolumeLevel((float)newVolume, NULL);
        }
        else if (scalar)
        {
            hr = endpointVolume->SetMasterVolumeLevelScalar((float)newVolume, NULL);
        }
        endpointVolume->Release();
    
        CoUninitialize();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a program using VB and I lost the source code but I
I made a program. I also made my own file type, which the program
I have made a program in c and wanted to see, how much memory
I'm trying to automate a program I made with a test suite via a
I made small program to divide large pictures and take part of them. When
I made a program in which I wanted to manually update the Data Grid
I made a program that opens an application, sleeps the thread for 500ms then
I made a program that is supposed to recognize a simple grammar. When I
i made a program that search logical drives to find a specific file .if
Made solution change: I am trying to display a html table of data.. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.