Programmatically Control the PC Volume in LabVIEW

Updated May 17, 2019

Reported In

Software

  • LabVIEW

Issue Details

I want to write a VI that allows me to programmatically change the volume of a waveform output device on my PC. How can I do this in LabVIEW?

Solution

To control the volume of your PC you will need to use a Call Library Function Node to call the dll's that you will need in LabVIEW. The dll file that you will need to access is the user32.dll this can be found in your computer under Windows >> System32 >> user32.dll. The VI that you will need to create will match that of the picture below. Please note that the constants going into Node B and Node C are configured as Hexadecimal.
.
The Call Library Function Nodes above should be configured as follows:

Node A Functions Tab

  • Library name or path contains user32.dll
  • Function name is set to FindWindowA
  • Thread is set to Run in UI thread
  • Calling convention is set to stdcall (WINAPI)

Node A Parameters Tab Prototypes should include the 3 following elements

  • hWnd - Type is set to Numeric, Data type is set to Unsigned 32-bit Integer, and Pass is set to Value
  • lpszClassName - Type is set to Numeric, Data type is set to Signed 32-bit Integer, and Pass is set to Value
  • lpszWindowName - Type is set to String, the Constant box is checked, String format is set to C String Pointer, Minimum size is set to <None>

Node B and Node C Functions Tab

  • Library name or path contains user32.dll
  • Function name is set to SendMessageA
  • Thread is set to Run in UI thread
  • Calling convention is set to stdcall (WINAPI)

Node B and Node C Parameters Tab Prototypes should include the 5 following elements

  • LRESULT  - Type is set to Numeric, Data type is set to Signed 32-bit Integer
  • hWnd - Type is set to Numeric, Data type is set to Unsigned 32-bit Integer, and Pass is set to Value
  • Msg - Type is set to Numeric, Data type is set to Unsigned 32-bit Integer, and Pass is set to Value
  • wParam - Type is set to Numeric, Data type is set to Unsigned 32-bit Integer, and Pass is set to Value
  • Iparam - Type is set to Numeric, Data type is set to Unsigned 32-bit Integer, and Pass is set to Value

Additional Information

This solution is only verified in the Windows 7 and Windows 10 Operating Systems.
The VI is also attached to this article below. 

Attachments

WAS THIS ARTICLE HELPFUL?

Not Helpful