#pragma warning disable IDE1006 // Naming Styles using System; using System.Runtime.InteropServices; using System.Text; namespace Vanara.PInvoke { /// Items from the WinMm.dll public static partial class WinMm { private const string Lib_Winmm = "winmm.dll"; /// Describes optional functionality supported by the auxiliary audio device. [PInvokeData("mmeapi.h", MSDNShortId = "NS:mmeapi.auxcaps_tag")] [Flags] public enum AUX_CAPS : uint { /// Supports volume control. AUXCAPS_VOLUME = 0x0001, /// Supports separate left and right volume control. AUXCAPS_LRVOLUME = 0x0002, } /// The auxGetDevCaps function retrieves the capabilities of a given auxiliary output device. /// /// /// Identifier of the auxiliary output device to be queried. Specify a valid device identifier (see the following comments section), /// or use the following constant: /// /// /// /// Value /// Meaning /// /// /// AUX_MAPPER /// Auxiliary audio mapper. The function returns an error if no auxiliary audio mapper is installed. /// /// /// /// Pointer to an AUXCAPS structure to be filled with information about the capabilities of the device. /// Size, in bytes, of the AUXCAPS structure. /// /// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following. /// /// /// Return code /// Description /// /// /// MMSYSERR_BADDEVICEID /// Specified device identifier is out of range. /// /// /// /// /// The device identifier in uDeviceID varies from zero to one less than the number of devices present. AUX_MAPPER may also be used. /// Use the auxGetNumDevs function to determine the number of auxiliary output devices present in the system. /// // https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-auxgetdevcaps MMRESULT auxGetDevCaps( UINT uDeviceID, // LPAUXCAPS pac, UINT cbac ); [DllImport(Lib_Winmm, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.auxGetDevCaps")] public static extern MMRESULT auxGetDevCaps(uint uDeviceID, out AUXCAPS pac, uint cbac); /// The auxGetNumDevs function retrieves the number of auxiliary output devices present in the system. /// Returns the number of device. A return value of zero means that no devices are present or that an error occurred. // https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-auxgetnumdevs UINT auxGetNumDevs(); [DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)] [PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.auxGetNumDevs")] public static extern uint auxGetNumDevs(); /// The auxGetVolume function retrieves the current volume setting of the specified auxiliary output device. /// Identifier of the auxiliary output device to be queried. /// /// /// Pointer to a variable to be filled with the current volume setting. The low-order word of this location contains the left /// channel volume setting, and the high-order word contains the right channel setting. A value of 0xFFFF represents full volume, /// and a value of 0x0000 is silence. /// /// /// If a device does not support both left and right volume control, the low-order word of the specified location contains the /// volume level. /// /// /// The full 16-bit setting(s) set with the auxSetVolume function are returned, regardless of whether the device supports the full /// 16 bits of volume-level control. /// /// /// /// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following. /// /// /// Return code /// Description /// /// /// MMSYSERR_BADDEVICEID /// Specified device identifier is out of range. /// /// /// /// /// /// Not all devices support volume control. To determine whether a device supports volume control, use the AUXCAPS_VOLUME flag to /// test the dwSupport member of the AUXCAPS structure (filled by the auxGetDevCaps function). /// /// /// To determine whether a device supports volume control on both the left and right channels, use the AUXCAPS_LRVOLUME flag to test /// the dwSupport member of the AUXCAPS structure (filled by auxGetDevCaps). /// /// // https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-auxgetvolume MMRESULT auxGetVolume( UINT uDeviceID, LPDWORD // pdwVolume ); [DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)] [PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.auxGetVolume")] public static extern MMRESULT auxGetVolume(uint uDeviceID, out uint pdwVolume); /// /// The auxOutMessage function sends a message to the given auxiliary output device. This function also performs error /// checking on the device identifier passed as part of the message. /// /// Identifier of the auxiliary output device to receive the message. /// Message to send. /// Message parameter. /// Message parameter. /// Returns the message return value. /// /// The /// DRV_QUERYDEVICEINTERFACE /// message queries for the device-interface name of a waveIn, waveOut, midiIn, midiOut, or mixer device. /// /// For /// DRV_QUERYDEVICEINTERFACE /// , dwParam1 is a pointer to a caller-allocated buffer into which the function writes a null-terminated Unicode string containing /// the device-interface name. If the device has no device interface, the string length is zero. /// /// For /// DRV_QUERYDEVICEINTERFACE /// , dwParam2 specifies the buffer size in bytes. This is an input parameter to the function. The caller should specify a size that /// is greater than or equal to the buffer size retrieved by the DRV_QUERYDEVICEINTERFACESIZE message. /// /// /// The DRV_QUERYDEVICEINTERFACE message is supported in Windows Me, and Windows 2000 and later. This message is valid only for the /// waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage functions. The system intercepts this message and /// returns the appropriate value without sending the message to the device driver. For general information about system-intercepted /// xxxMessage functions, see System-Intercepted Device Messages. /// /// The following two message constants are used together for the purpose of obtaining device interface names: /// /// /// DRV_QUERYDEVICEINTERFACESIZE /// /// /// DRV_QUERYDEVICEINTERFACE /// /// /// /// The first message obtains the size in bytes of the buffer needed to hold the string containing the device interface name. The /// second message retrieves the name string in a buffer of the required size. /// /// For more information, see Obtaining a Device Interface Name. /// The /// DRV_QUERYDEVICEINTERFACESIZE /// message queries for the size of the buffer required to hold the device-interface name. /// /// For /// DRV_QUERYDEVICEINTERFACESIZE /// , dwParam1 is a pointer to buffer size. This parameter points to a ULONG variable into which the function writes the required /// buffer size in bytes. The size includes storage space for the name string's terminating null. The size is zero if the device ID /// identifies a device that has no device interface. /// /// For /// DRV_QUERYDEVICEINTERFACESIZE /// , dwParam2 is unused. Set this parameter to zero. /// /// /// This message is valid only for the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage functions. The /// system intercepts this message and returns the appropriate value without sending the message to the device driver. For general /// information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages. /// /// /// The buffer size retrieved by this message is expressed as a byte count. It specifies the size of the buffer needed to hold the /// null-terminated Unicode string that contains the device-interface name. The caller allocates a buffer of the specified size and /// uses the DRV_QUERYDEVICEINTERFACE message to retrieve the device-interface name string. /// /// For more information, see Obtaining a Device Interface Name. /// The /// DRV_QUERYDEVNODE /// message queries for the devnode number assigned to the device by the Plug and Play manager. /// /// For /// DRV_QUERYDEVNODE /// , dwParam1 is a pointer to a caller-allocated DWORD variable into which the function writes the devnode number. If no devnode is /// assigned to the device, the function sets this variable to zero. /// /// For /// DRV_QUERYDEVNODE /// , dwParam2 is unused. Set this parameter to zero. /// /// /// In Windows 2000 and later, the message always returns MMSYSERR_NOTSUPPORTED. This message is valid only for the waveInMessage, /// waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage functions. The system intercepts this message and returns the /// appropriate value without sending the message to the device driver. For general information about system-intercepted /// xxxMessage functions, see System-Intercepted Device Messages. /// /// The /// DRV_QUERYMAPPABLE /// message queries for whether the specified device can be used by a mapper. /// /// For /// DRV_QUERYMAPPABLE /// , dwParam1 is unused. Set this parameter to zero. /// /// For /// DRV_QUERYMAPPABLE /// , dwParam2 is unused. Set this parameter to zero. /// /// /// This message is valid only for the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, mixerMessage and /// auxOutMessage functions. The system intercepts this message and returns the appropriate value without sending the message /// to the device driver. For general information about system-intercepted xxxMessage functions, see System-Intercepted /// Device Messages. /// /// /// When an application program opens a mapper instead of a specific audio device, the system inserts a mapper between the /// application and the available devices. The mapper selects an appropriate device by mapping the application's requirements to one /// of the available devices. For more information about mappers, see the Microsoft Windows SDK documentation. /// /// The /// DRVM_MAPPER_CONSOLEVOICECOM_GET /// message retrieves the device ID of the preferred voice-communications device. /// /// For /// DRVM_MAPPER_CONSOLEVOICECOM_GET /// , dwParam1 is a pointer to device ID. This parameter points to a DWORD variable into which the function writes the device ID of /// the current preferred voice-communications device. The function writes the value (-1) if no device is available that qualifies /// as a preferred voice-communications device. /// /// For /// DRVM_MAPPER_CONSOLEVOICECOM_GET /// , dwParam2 is a pointer to status flags. This parameter points to a DWORD variable into which the function writes the /// device-status flags. Only one flag bit is currently defined: DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY. /// /// /// This message is valid only for the waveInMessage and waveOutMessage functions. When a caller calls these two functions with the /// DRVM_MAPPER_CONSOLEVOICECOM_GET message, the caller must specify the device ID as WAVE_MAPPER, and then cast this value to the /// appropriate handle type. For the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, or mixerMessage /// functions, the caller must cast the device ID to a handle of type HWAVEIN, HWAVEOUT, HMIDIIN, HMIDIOUT, or HMIXER, respectively. /// Note that if the caller supplies a valid handle instead of a device ID for this parameter, the function fails and returns error /// code MMSYSERR_NOSUPPORT. /// /// /// The system intercepts this message and returns the appropriate value without sending the message to the device driver. For /// general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages. /// /// /// This message provides a way to determine which device is preferred specifically for voice communications, in contrast to the /// DRVM_MAPPER_PREFERRED_GET message, which determines which device is preferred for all other audio functions. /// /// /// For example, the preferred waveOut device for voice communications might be the earpiece in a headset, but the preferred /// waveOut device for all other audio functions might be a set of stereo speakers. /// /// /// When the DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY flag bit is set in the DWORD location pointed to by dwParam2, the /// waveIn and waveOut APIs use only the current preferred voice-communications device and do not search for other /// available devices if the preferred device is unavailable. The flag that is output by either the waveInMessage or /// waveOutMessage call applies to the preferred voice-communications device for both the waveIn and waveOut /// APIs, regardless of whether the call is made to waveInMessage or waveOutMessage. For more information, see /// Preferred Voice-Communications Device ID. /// /// The /// DRVM_MAPPER_PREFERRED_GET /// message retrieves the device ID of the preferred audio device. /// /// For /// DRVM_MAPPER_PREFERRED_GET /// , dwParam1 is a pointer to device ID. This parameter points to a DWORD variable into which the function writes the device ID of /// the current preferred device. The function writes the value (-1) if no device is available that qualifies as a preferred device. /// /// For /// DRVM_MAPPER_PREFERRED_GET /// , dwParam2 is a pointer to status flags. This parameter points to a DWORD variable into which the function writes the /// device-status flags. Only one flag bit is currently defined (for waveInMessage and waveOutMessage calls only): DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY. /// /// /// This message is valid only for the waveInMessage, waveOutMessage and midiOutMessage functions. When the caller calls these /// functions with the DRVM_MAPPER_PREFERRED_GET message, the caller must first specify the device ID as WAVE_MAPPER (for /// waveInMessage or waveOutMessage) or MIDI_MAPPER (for midiOutMessage), and then cast this value to the /// appropriate handle type. For the waveInMessage, waveOutMessage, or midiOutMessage functions, the caller /// must cast the device ID to a handle type HWAVEIN, HWAVEOUT or HMIDIOUT, respectively. Note that if the caller supplies a valid /// handle instead of a device ID for this parameter, the function fails and returns error code MMSYSERR_NOSUPPORT. /// /// /// The system intercepts this message and returns the appropriate value without sending the message to the device driver. For /// general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages. /// /// /// This message provides a way to determine which device is preferred for audio functions in general, in contrast to the /// DRVM_MAPPER_CONSOLEVOICECOM_GET message, which determines which device is preferred specifically for voice communications. /// /// /// When the DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY flag bit is set in the DWORD location pointed to by dwParam2, the /// waveIn and waveOut APIs use only the current preferred device and do not search for other available devices if the /// preferred device is unavailable. Note that the midiOutMessage function does not output this flag--the midiOut API /// always uses only the preferred device. The flag that is output by either the waveInMessage or waveOutMessage call /// applies to the preferred device for both the waveIn and waveOut APIs, regardless of whether the call is made to /// waveInMessage or waveOutMessage. /// /// /// The xxxMessage functions accept this value in place of a valid device handle in order to allow an application to determine the /// default device ID without first having to open a device. For more information, see Accessing the Preferred Device ID. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-auxoutmessage MMRESULT auxOutMessage( UINT uDeviceID, UINT // uMsg, DWORD_PTR dw1, DWORD_PTR dw2 ); [DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)] [PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.auxOutMessage")] public static extern MMRESULT auxOutMessage(uint uDeviceID, uint uMsg, IntPtr dw1, IntPtr dw2); /// The auxSetVolume function sets the volume of the specified auxiliary output device. /// /// Identifier of the auxiliary output device to be queried. Device identifiers are determined implicitly from the number of devices /// present in the system. Device identifier values range from zero to one less than the number of devices present. Use the /// auxGetNumDevs function to determine the number of auxiliary devices in the system. /// /// /// /// Specifies the new volume setting. The low-order word specifies the left-channel volume setting, and the high-order word /// specifies the right-channel setting. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence. /// /// /// If a device does not support both left and right volume control, the low-order word of dwVolume specifies the volume level, and /// the high-order word is ignored. /// /// /// /// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following. /// /// /// Return code /// Description /// /// /// MMSYSERR_BADDEVICEID /// Specified device identifier is out of range. /// /// /// /// /// /// Not all devices support volume control. To determine whether the device supports volume control, use the AUXCAPS_VOLUME flag to /// test the dwSupport member of the AUXCAPS structure (filled by the auxGetDevCaps function). /// /// /// To determine whether the device supports volume control on both the left and right channels, use the AUXCAPS_LRVOLUME flag to /// test the dwSupport member of the AUXCAPS structure (filled by auxGetDevCaps). /// /// /// Most devices do not support the full 16 bits of volume-level control and will use only the high-order bits of the requested /// volume setting. For example, for a device that supports 4 bits of volume control, requested volume level values of 0x4000, /// 0x4FFF, and 0x43BE will produce the same physical volume setting, 0x4000. The auxGetVolume function will return the full 16-bit /// setting set with auxSetVolume. /// /// /// Volume settings are interpreted logarithmically. This means the perceived volume increase is the same when increasing the volume /// level from 0x5000 to 0x6000 as it is from 0x4000 to 0x5000. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-auxsetvolume MMRESULT auxSetVolume( UINT uDeviceID, DWORD // dwVolume ); [DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)] [PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.auxSetVolume")] public static extern MMRESULT auxSetVolume(uint uDeviceID, uint dwVolume); /// The AUXCAPS structure describes the capabilities of an auxiliary output device. // https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/ns-mmeapi-auxcaps typedef struct auxcaps_tag { WORD wMid; WORD wPid; // VERSION vDriverVersion; char szPname[MAXPNAMELEN]; WORD wTechnology; DWORD dwSupport; } AUXCAPS, *PAUXCAPS, *NPAUXCAPS, *LPAUXCAPS; [PInvokeData("mmeapi.h", MSDNShortId = "NS:mmeapi.auxcaps_tag")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct AUXCAPS { /// /// Manufacturer identifier for the device driver for the auxiliary audio device. Manufacturer identifiers are defined in /// Manufacturer and Product Identifiers. /// public ushort wMid; /// /// Product identifier for the auxiliary audio device. Currently, no product identifiers are defined for auxiliary audio devices. /// public ushort wPid; /// /// Version number of the device driver for the auxiliary audio device. The high-order byte is the major version number, and the /// low-order byte is the minor version number. /// public uint vDriverVersion; /// Product name in a null-terminated string. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string szPname; /// /// Type of the auxiliary audio output: /// /// /// Name /// Description /// /// /// AUXCAPS_AUXIN /// Audio output from auxiliary input jacks. /// /// /// AUXCAPS_CDAUDIO /// Audio output from an internal CD-ROM drive. /// /// /// public ushort wTechnology; /// /// Describes optional functionality supported by the auxiliary audio device. /// /// /// Name /// Description /// /// /// AUXCAPS_LRVOLUME /// Supports separate left and right volume control. /// /// /// AUXCAPS_VOLUME /// Supports volume control. /// /// /// /// If a device supports volume changes, the AUXCAPS_VOLUME flag will be set. If a device supports separate volume changes on /// the left and right channels, both AUXCAPS_VOLUME and the AUXCAPS_LRVOLUME will be set. /// /// public AUX_CAPS dwSupport; } /* MM_WIM_CLOSE MM_WIM_DATA MM_WIM_OPEN MM_WOM_CLOSE MM_WOM_DONE MM_WOM_OPEN WIM_CLOSE WIM_DATA WIM_OPEN WOM_CLOSE WOM_DONE WOM_OPEN */ } }