Page 1 of 1

[Solved] Mic - turn on/off

Posted: Tue Jun 09, 2020 12:42 pm
by ZX80
Hello, everyone.

I wanted to ask for help from those who understand the interfaces well. The goal of the task is in the title. How can I solve this ?
In fact, in the fourth paragraph/step, select the "Properties" item and then go to the "levels"-tab. Now you can see desired button. So... it's very long path (the setting is hidden very deep). Unfortunately, when using the applet, I can only get halfway:

Code: Select all

"C:\WINDOWS\system32\rundll32.exe" shell32.dll,Control_RunDLL mmsys.cpl,,recording
And then it is not reliable to emulate keystrokes.

Yes, I know that this problem can be solved using third-party programs, such as: devcon & nircmd (link). It says here how to do it.

And:

Code: Select all

[b]nircmd.exe[/b] mutesysvolume 2 microphone 2
I just thought that it can be done on PB.

In this topic, CELTIC88 controls the system volume. And he used Interface, so I asked about it. I only need to turn on/off the microphone.


I would like a solution for Windows Vista/7 and higher.
Thanks in advance.

Re: Mic - turn on/off

Posted: Tue Jun 09, 2020 1:11 pm
by Olli
What type of information you get when you execute the code of CELTIC88 ?

(error ? which error message ?)

Re: Mic - turn on/off

Posted: Tue Jun 09, 2020 2:25 pm
by ZX80
Olli, thanks for your reply.

There is no mistake. Its code works great. The problem is that I need to solve another task. Not master-volume control, but microphone control. I already wrote about it in my first post.

P.S. I gave a link to the CELTIC88 code to show an example (I think that my task should be solved using interfaces). This is the main reason.

Re: Mic - turn on/off

Posted: Wed Jun 10, 2020 7:50 am
by infratec
Not really tested but as a startpoint:

Code: Select all

Interface IMMDeviceEnumerator Extends IUnknown
  EnumAudioEndpoints()
  GetDefaultAudioEndpoint(Flow.l, role.l, IMMDevice.i)       
  GetDevice()       
  RegisterEndpointNotificationCallback()
  UnregisterEndpointNotificationCallback()
EndInterface

Interface IAudioEndpointVolume Extends IUnknown
  RegisterControlChangeNotify()
  UnregisterControlChangeNotify()
  GetChannelCount()
  SetMasterVolumeLevel()
  SetMasterVolumeLevelScalar()
  GetMasterVolumeLevel()
  GetMasterVolumeLevelScalar()
  SetChannelVolumeLevel()
  SetChannelVolumeLevelScalar()
  GetChannelVolumeLevel()
  GetChannelVolumeLevelScalar()
  SetMute(bMute.i, *guidEventContext)
  GetMute(*pbMute)
  GetVolumeStepInfo()
  VolumeStepUp(*context)
  VolumeStepDown(*context)
  QueryHardwareSupport()
  GetVolumeRange()
EndInterface

Interface IMMDevice Extends IUnknown
  Activate(iid, dwClsCtx.l, *pActivationParams, *ppInterface)
  OpenPropertyStore()
  GetId()
  GetState()
EndInterface 


DataSection
  
  IAudioEndpointVolume:
  Data.l $5CDF2C82
  Data.w $841E,$4546
  Data.b $97,$22,$0C,$F7,$40,$78,$22,$9A
 
  MMDeviceEnumerator:
  Data.l $BCDE0395
  Data.w $E52F,$467C
  Data.b $8E,$3D,$C4,$57,$92,$91,$69,$2E
 
  IMMDeviceEnumerator:
  Data.l $A95664D2
  Data.w $9614
  Data.w $4F35
  Data.b $A7,$46,$DE,$8D,$B6,$36,$17,$E6
  
EndDataSection


Define deviceEnumerator.IMMDeviceEnumerator
Define defaultDevice.IMMDevice
Define endpointVolume.IAudioEndpointVolume
Define MuteState.i

CoInitialize_(#Null)

CoCreateInstance_(?MMDeviceEnumerator, 0, 1, ?IMMDeviceEnumerator, @deviceEnumerator)
If deviceEnumerator

  deviceEnumerator\GetDefaultAudioEndpoint(0, 0, @defaultDevice)

  deviceEnumerator\Release()
  
  If defaultDevice
    defaultDevice\Activate(?IAudioEndpointVolume, 1, 0, @endpointVolume)
    defaultDevice\Release()
    
    If endpointVolume
      
      endpointVolume\GetMute(@MuteState)
      Debug MuteState
      
      If MessageRequester("Mute", "Mute On?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
      
        endpointVolume\SetMute(#True, #Null)
        endpointVolume\GetMute(@MuteState)
        Debug MuteState
        
        If MessageRequester("Mute", "Mute Off?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
          endpointVolume\SetMute(#False, #Null)
          endpointVolume\GetMute(@MuteState)
          Debug MuteState
        EndIf
      EndIf

      endpointVolume\Release()
    EndIf
  EndIf
EndIf
CoUninitialize_()

Re: Mic - turn on/off

Posted: Wed Jun 10, 2020 8:27 am
by ZX80
infratec, many thanks!

I really appreciate your help. It's true. But... I'm crying. Because you don't understand me. It's my fault. My bad english, of course(with google-translator). Anyway, thanks for your reply. Your code does manipulations with master volume(mute/unmute). Yes, it does. And working well, but I asked about another thing. Okay. I will try to find solution if I can. Thanks again.

I looked here, but didn't find nothing, any methods for the microphone manipulations. Maybe I'm looking again not good enough.

How do they do it? Skype... etc.

Re: Mic - turn on/off

Posted: Wed Jun 10, 2020 8:30 am
by infratec
Hm...

in my opinion it does it for a device and not for master.
But my example uses the default device.

I will check what I can do.

Re: Mic - turn on/off

Posted: Wed Jun 10, 2020 8:51 am
by ZX80
infratec, thanks a lot !!!

Please take your time. You already helped me a lot. In other topics, too. I'm afraid to ask: my limit is not over yet? I hope no. Because I try to ask only difficult questions(for me). Which I can’t understand on my own.

P.S. Interfaces for me are like a Chinese letter.

Re: Mic - turn on/off

Posted: Wed Jun 10, 2020 10:43 am
by infratec
Hi,

this mutes my only capture device which I have:

Code: Select all

EnableExplicit

#DEVICE_STATE_ACTIVE = 1
#DEVICE_STATE_DISABLED = 2
#DEVICE_STATE_NOTPRESENT = 4
#DEVICE_STATE_UNPLUGGED = 8
#DEVICE_STATEMASK_ALL = $F


Enumeration
  #eRender
  #eCapture
  #eAll
  #EDataFlow_enum_count
EndEnumeration

Structure tag_inner_PROPVARIANT
  vt.i
  wReserved1.u
  wReserved2.u
  wReserved3.u
  StructureUnion
    *pszVal
    *pwszVal
  EndStructureUnion
EndStructure

Structure PROPVARIANT
  StructureUnion
    p.tag_inner_PROPVARIANT
    decVal.i
  EndStructureUnion
EndStructure


Interface IMMDeviceEnumerator Extends IUnknown
  EnumAudioEndpoints(dataFlow.i, dwStateMask.l, *pDevices)
  GetDefaultAudioEndpoint(Flow.l, role.l, IMMDevice.i)       
  GetDevice(*wstrId, *pDevice)
  RegisterEndpointNotificationCallback()
  UnregisterEndpointNotificationCallback()
EndInterface

Interface IAudioEndpointVolume Extends IUnknown
  RegisterControlChangeNotify()
  UnregisterControlChangeNotify()
  GetChannelCount()
  SetMasterVolumeLevel()
  SetMasterVolumeLevelScalar()
  GetMasterVolumeLevel()
  GetMasterVolumeLevelScalar()
  SetChannelVolumeLevel()
  SetChannelVolumeLevelScalar()
  GetChannelVolumeLevel()
  GetChannelVolumeLevelScalar()
  SetMute(bMute.i, *guidEventContext)
  GetMute(*pbMute)
  GetVolumeStepInfo()
  VolumeStepUp(*context)
  VolumeStepDown(*context)
  QueryHardwareSupport()
  GetVolumeRange()
EndInterface

Interface IMMDeviceCollection Extends IUnknown
  GetCount(*cDevices)
  Item(nDevice.i, *pDevice)
EndInterface


Interface IMMDevice Extends IUnknown
  Activate(iid, dwClsCtx.l, *pActivationParams, *ppInterface)
  OpenPropertyStore(stgmAccess.l, *pProperties)
  GetId()
  GetState()
EndInterface

Interface IPropertyStore Extends IUnknown
  GetCount(*cProps)
  GetAt(iProp.l, *key)
  GetValue(key, *v)
  SetValue(key, propvar)
  Commit()
EndInterface


DataSection
  
  IAudioEndpointVolume:
  Data.l $5CDF2C82
  Data.w $841E,$4546
  Data.b $97,$22,$0C,$F7,$40,$78,$22,$9A
 
  MMDeviceEnumerator:
  Data.l $BCDE0395
  Data.w $E52F,$467C
  Data.b $8E,$3D,$C4,$57,$92,$91,$69,$2E
 
  IMMDeviceEnumerator:
  Data.l $A95664D2
  Data.w $9614, $4F35
  Data.b $A7,$46,$DE,$8D,$B6,$36,$17,$E6
  
  ;https://doxygen.reactos.org/d2/d1f/mmdeviceapi_8idl_source.html
  IMMDeviceCollection:
  Data.l $0bd7a1be
  Data.w $7a1a,$44db
  Data.b $83,$97,$cc,$53,$92,$38,$7b,$5e
  
  ;https://doxygen.reactos.org/d8/dbf/propsys_8idl_source.html
  IPropertyStore:
  Data.l $886d8eeb
  Data.w $8cf2,$4446
  Data.b $8d,$02,$cd,$ba,$1d,$bd,$cf,$99
  
  PKEY_Device_FriendlyName:
  Data.l $a45c254e
  Data.w $df1c,$4efd
  Data.b $80,$20,$67,$d1,$46,$a8,$50,$e0
  
EndDataSection


Define deviceEnumerator.IMMDeviceEnumerator
Define deviceCollection.IMMDeviceCollection
Define device.IMMDevice
Define endpointVolume.IAudioEndpointVolume
Define *props.IPropertyStore
Define MuteState.i, Count.i, i.i
Define v.propvariant

CoInitialize_(#Null)

CoCreateInstance_(?MMDeviceEnumerator, 0, 1, ?IMMDeviceEnumerator, @deviceEnumerator)
If deviceEnumerator
  
  deviceEnumerator\EnumAudioEndpoints(#eCapture, #DEVICE_STATE_ACTIVE, @deviceCollection)
  If deviceCollection
    deviceCollection\GetCount(@Count)
    Debug Count
    ;For i = 0 To Count - 1
      deviceCollection\Item(0, @device)
      ;If device
        
        
;         device\OpenPropertyStore(#STGM_READ, @*props)
;         If *props
; 
;           *props\GetValue(?PKEY_Device_FriendlyName, @v)
;           Debug v\bstrVal
;           Debug PeekS(v\bstrVal)
        ;EndIf
        ;device\Release()
      ;EndIf
    ;Next i
    
    deviceCollection\Release()
  EndIf
  
  ;deviceEnumerator\GetDefaultAudioEndpoint(0, 0, @device)

  deviceEnumerator\Release()
 
  If device
    device\Activate(?IAudioEndpointVolume, 1, 0, @endpointVolume)
    device\Release()
   
    If endpointVolume
     
      endpointVolume\GetMute(@MuteState)
      Debug MuteState
     
      If MessageRequester("Mute", "Mute On?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
     
        endpointVolume\SetMute(#True, #Null)
        endpointVolume\GetMute(@MuteState)
        Debug MuteState
       
        If MessageRequester("Mute", "Mute Off?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
          endpointVolume\SetMute(#False, #Null)
          endpointVolume\GetMute(@MuteState)
          Debug MuteState
        EndIf
      EndIf

      endpointVolume\Release()
    EndIf
  EndIf
EndIf
CoUninitialize_()

Re: [Solved] Mic - turn on/off

Posted: Wed Jun 10, 2020 11:28 am
by ZX80
infratec :!:

Brilliant! What the doctor prescribed. These pills are just a miracle. :mrgreen:
Thank you so much! As always, top notch quality!

infratec, You made my day so happy and shine. Thank you again and again.
For every time you answer. I wish you good luck. And thanks for your gift.
I think other people will someday find your code useful too.

P.S. Yes, I also tested with only one recording device (on my laptop).


Best regards

Re: [Solved] Mic - turn on/off

Posted: Wed Jun 10, 2020 11:55 am
by infratec
I reduced it to the first capturedevice, because it was to complicated to get the name of the devices.
The PropertyVariantStructure is to define and that was to much work.

If you get older and better :wink: help other people who ask for help.
That's the price you have to pay for my help.

Re: [Solved] Mic - turn on/off

Posted: Wed Jun 10, 2020 12:45 pm
by ZX80
infratec :!:
I reduced it to the first capturedevice, because it was to complicated to get the name of the devices.
The PropertyVariantStructure is to define and that was to much work.
Okay. The main thing it does what I need.
That's the price you have to pay for my help.
I agree with you. Absolutely. If I can do somewhat for someone, then I don't live in vain.

... You said that, and I remembered one good movie. I first saw it some months ago. But this film was made about 20 years ago. The title of movie is: "Pay It Forward". If you have time, check it out. Hope you don’t regret taking the time for it. The last scene just killed me. And this song: "Calling All Angels" by Jane Siberry & KD Lang. It makes me cry. I don't why? Maybe it's because I'm already too old. Or I'm very sentimental. Or it's a really good movie.

So... I think I know what you wanted to tell me.


Please, this is not ad or chat.
I'm so sorry for offtopic. :oops:

Re: [Solved] Mic - turn on/off

Posted: Sat Oct 10, 2020 9:33 pm
by wb2k
infratec wrote:I reduced it to the first capturedevice, because it was to complicated to get the name of the devices.
The PropertyVariantStructure is to define and that was to much work.
...
I have found PropertyVariantStructure for tag_inner_PROPVARIANT at http://forums.purebasic.com/english/vie ... 19#p489813
However, I get an empty PropertyVariantStructure back although "GetValue" on the device is successful. Anyone has an idea?

Thanks!

infratec's Code with PropertyVariantStructure:

Code: Select all

EnableExplicit

#DEVICE_STATE_ACTIVE = 1
#DEVICE_STATE_DISABLED = 2
#DEVICE_STATE_NOTPRESENT = 4
#DEVICE_STATE_UNPLUGGED = 8
#DEVICE_STATEMASK_ALL = $F


Enumeration
  #eRender
  #eCapture
  #eAll
  #EDataFlow_enum_count
EndEnumeration

Structure PROPVARIANT_CLIPDATA
  cbSize.l
  ulClipFmt.l
  *pClipData.BYTE
EndStructure

Structure PROPVARIANT_BSTRBLOB
  cbSize.l
  *pData.BYTE
EndStructure

Structure PROPVARIANT_BLOB
  cbSize.l
  *pBlobData.BYTE
EndStructure

Structure PROPVARIANT_VERSIONEDSTREAM
  guidVersion.GUID
  *pStream.IStream
EndStructure

Structure PROPVARIANT_CAC
  cElems.l
  *pElems.BYTE
EndStructure

Structure PROPVARIANT_CAUB
  cElems.l
  *pElems.BYTE
EndStructure

Structure PROPVARIANT_CAI
  cElems.l
  *pElems.WORD
EndStructure

Structure PROPVARIANT_CAUI
  cElems.l
  *pElems.WORD
EndStructure

Structure PROPVARIANT_CAL
  cElems.l
  *pElems.LONG
EndStructure

Structure PROPVARIANT_CAUL
  cElems.l
  *pElems.LONG
EndStructure

Structure PROPVARIANT_CAFLT
  cElems.l
  *pElems.FLOAT
EndStructure

Structure PROPVARIANT_CADBL
  cElems.l
  *pElems.DOUBLE
EndStructure

Structure PROPVARIANT_CACY
  cElems.l
  *pElems.QUAD
EndStructure

Structure PROPVARIANT_CADATE
  cElems.l
  *pElems.DOUBLE
EndStructure

Structure PROPVARIANT_CABSTR
  cElems.l
  *pElems.INTEGER
EndStructure

Structure PROPVARIANT_CABSTRBLOB
  cElems.l
  *pElems.PROPVARIANT_BSTRBLOB
EndStructure

Structure PROPVARIANT_CABOOL
  cElems.l
  *pElems.WORD
EndStructure

Structure PROPVARIANT_CASCODE
  cElems.l
  *pElems.LONG
EndStructure

Structure PROPVARIANT_CAPROPVARIANT
  cElems.l
  *pElems.PROPVARIANT
EndStructure

Structure PROPVARIANT_CAH
  cElems.l
  *pElems.QUAD
EndStructure

Structure PROPVARIANT_CAUH
  cElems.l
  *pElems.QUAD
EndStructure

Structure PROPVARIANT_CALPSTR
  cElems.l
  *pElems.INTEGER
EndStructure

Structure PROPVARIANT_CALPWSTR
  cElems.l
  *pElems.INTEGER
EndStructure

Structure PROPVARIANT_CAFILETIME
  cElems.l
  *pElems.FILETIME
EndStructure

Structure PROPVARIANT_CACLIPDATA
  cElems.l
  *pElems.PROPVARIANT_CLIPDATA
EndStructure

Structure PROPVARIANT_CACLSID
  cElems.l
  *pElems.CLSID
EndStructure

Structure tag_inner_PROPVARIANT Align #PB_Structure_AlignC
  vt.w
  wReserved1.w
  wReserved2.w
  wReserved3.w
  StructureUnion
    cVal.b
    bVal.b
    iVal.w
    uiVal.w
    lVal.l
    ulVal.l
    intVal.l
    uintVal.l
    hVal.q
    uhVal.q
    fltVal.f
    dblVal.d
    boolVal.w
    scode.l
    cyVal.q
    date.d
    filetime.FILETIME
    *puuid.CLSID
    *pclipdata.PROPVARIANT_CLIPDATA
    bstrVal.i
    bstrblobVal.PROPVARIANT_BSTRBLOB
    blob.PROPVARIANT_BLOB
    *pszVal
    *pwszVal
    *punkVal.IUnknown
    *pdispVal.IDispatch
    *pStream.IStream
    *pStorage.IStorage
    *pVersionedStream.PROPVARIANT_VERSIONEDSTREAM
    *parray.SAFEARRAY
    cac.PROPVARIANT_CAC
    caub.PROPVARIANT_CAUB
    cai.PROPVARIANT_CAI
    caui.PROPVARIANT_CAUI
    cal.PROPVARIANT_CAL
    caul.PROPVARIANT_CAUL
    cah.PROPVARIANT_CAH
    cauh.PROPVARIANT_CAUH
    caflt.PROPVARIANT_CAFLT
    cadbl.PROPVARIANT_CADBL
    cabool.PROPVARIANT_CABOOL
    cascode.PROPVARIANT_CASCODE
    cacy.PROPVARIANT_CACY
    cadate.PROPVARIANT_CADATE
    cafiletime.PROPVARIANT_CAFILETIME
    cauuid.PROPVARIANT_CACLSID
    caclipdata.PROPVARIANT_CACLIPDATA
    cabstr.PROPVARIANT_CABSTR
    cabstrblob.PROPVARIANT_CABSTRBLOB
    calpstr.PROPVARIANT_CALPSTR
    calpwstr.PROPVARIANT_CALPWSTR
    capropvar.PROPVARIANT_CAPROPVARIANT
    *pcVal.BYTE
    *pbVal.BYTE
    *piVal.WORD
    *puiVal.WORD
    *plVal.LONG
    *pulVal.LONG
    *pintVal.LONG
    *puintVal.LONG
    *pfltVal.FLOAT
    *pdblVal.DOUBLE
    *pboolVal.WORD
    *pdecVal.VARIANT_DECIMAL
    *pscode.LONG
    *pcyVal.QUAD
    *pdate.DOUBLE
    *pbstrVal.INTEGER
    *ppunkVal.INTEGER
    *ppdispVal.INTEGER
    *pparray.INTEGER
    *pvarVal.PROPVARIANT
  EndStructureUnion
EndStructure

Structure PROPVARIANT
  StructureUnion
    p.tag_inner_PROPVARIANT
    decVal.i
  EndStructureUnion
EndStructure


Interface IMMDeviceEnumerator Extends IUnknown
  EnumAudioEndpoints(dataFlow.i, dwStateMask.l, *pDevices)
  GetDefaultAudioEndpoint(Flow.l, role.l, IMMDevice.i)       
  GetDevice(*wstrId, *pDevice)
  RegisterEndpointNotificationCallback()
  UnregisterEndpointNotificationCallback()
EndInterface

Interface IAudioEndpointVolume Extends IUnknown
  RegisterControlChangeNotify()
  UnregisterControlChangeNotify()
  GetChannelCount()
  SetMasterVolumeLevel()
  SetMasterVolumeLevelScalar()
  GetMasterVolumeLevel()
  GetMasterVolumeLevelScalar()
  SetChannelVolumeLevel()
  SetChannelVolumeLevelScalar()
  GetChannelVolumeLevel()
  GetChannelVolumeLevelScalar()
  SetMute(bMute.i, *guidEventContext)
  GetMute(*pbMute)
  GetVolumeStepInfo()
  VolumeStepUp(*context)
  VolumeStepDown(*context)
  QueryHardwareSupport()
  GetVolumeRange()
EndInterface

Interface IMMDeviceCollection Extends IUnknown
  GetCount(*cDevices)
  Item(nDevice.i, *pDevice)
EndInterface


Interface IMMDevice Extends IUnknown
  Activate(iid, dwClsCtx.l, *pActivationParams, *ppInterface)
  OpenPropertyStore(stgmAccess.l, *pProperties)
  GetId()
  GetState()
EndInterface

Interface IPropertyStore Extends IUnknown
  GetCount(*cProps)
  GetAt(iProp.l, *key)
  GetValue(key, *v)
  SetValue(key, propvar)
  Commit()
EndInterface


DataSection
 
  IAudioEndpointVolume:
  Data.l $5CDF2C82
  Data.w $841E,$4546
  Data.b $97,$22,$0C,$F7,$40,$78,$22,$9A
 
  MMDeviceEnumerator:
  Data.l $BCDE0395
  Data.w $E52F,$467C
  Data.b $8E,$3D,$C4,$57,$92,$91,$69,$2E
 
  IMMDeviceEnumerator:
  Data.l $A95664D2
  Data.w $9614, $4F35
  Data.b $A7,$46,$DE,$8D,$B6,$36,$17,$E6
 
  ;https://doxygen.reactos.org/d2/d1f/mmdeviceapi_8idl_source.html
  IMMDeviceCollection:
  Data.l $0bd7a1be
  Data.w $7a1a,$44db
  Data.b $83,$97,$cc,$53,$92,$38,$7b,$5e
 
  ;https://doxygen.reactos.org/d8/dbf/propsys_8idl_source.html
  IPropertyStore:
  Data.l $886d8eeb
  Data.w $8cf2,$4446
  Data.b $8d,$02,$cd,$ba,$1d,$bd,$cf,$99
 
  PKEY_Device_FriendlyName:
  Data.l $a45c254e
  Data.w $df1c,$4efd
  Data.b $80,$20,$67,$d1,$46,$a8,$50,$e0
 
EndDataSection


Define deviceEnumerator.IMMDeviceEnumerator
Define deviceCollection.IMMDeviceCollection
Define device.IMMDevice
Define endpointVolume.IAudioEndpointVolume
Define *props.IPropertyStore
Define MuteState.i, Count.i, i.i
Define v.propvariant

CoInitialize_(#Null)

CoCreateInstance_(?MMDeviceEnumerator, 0, 1, ?IMMDeviceEnumerator, @deviceEnumerator)
If deviceEnumerator
 
  deviceEnumerator\EnumAudioEndpoints(#eCapture, #DEVICE_STATE_ACTIVE, @deviceCollection)
  If deviceCollection
    deviceCollection\GetCount(@Count)
    Debug Count
    For i = 0 To Count - 1
      deviceCollection\Item(i, @device)
      If device
       
        device\OpenPropertyStore(#STGM_READ, @*props)
        If *props
          *props\GetValue(?PKEY_Device_FriendlyName, @v)
          Debug v\p\bstrVal
          Debug PeekS(v\p\bstrVal)
        EndIf
        device\Release()
      EndIf
    Next i
   
    deviceCollection\Release()
  EndIf
 
  ;deviceEnumerator\GetDefaultAudioEndpoint(0, 0, @device)

  deviceEnumerator\Release()
 
  If device
    device\Activate(?IAudioEndpointVolume, 1, 0, @endpointVolume)
    device\Release()
   
    If endpointVolume
     
      endpointVolume\GetMute(@MuteState)
      Debug MuteState
     
      If MessageRequester("Mute", "Mute On?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
     
        endpointVolume\SetMute(#True, #Null)
        endpointVolume\GetMute(@MuteState)
        Debug MuteState
       
        If MessageRequester("Mute", "Mute Off?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
          endpointVolume\SetMute(#False, #Null)
          endpointVolume\GetMute(@MuteState)
          Debug MuteState
        EndIf
      EndIf

      endpointVolume\Release()
    EndIf
  EndIf
EndIf
CoUninitialize_()

Re: [Solved] Mic - turn on/off

Posted: Thu Feb 03, 2022 3:29 pm
by infratec
I just found out that the datasection for

Code: Select all

PKEY_Device_FriendlyName
is wrong.

The PID field is missing:

Code: Select all

PKEY_Device_FriendlyName:
  Data.l $a45c254e
  Data.u $df1c,$4efd
  Data.a $80,$20,$67,$d1,$46,$a8,$50,$e0
  Data.l 14
You can find a listing at:
https://hackage.haskell.org/package/bin ... _devpkey.h