using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class WinMm
{
/// max oem vxd name length (including NULL)
public const int MAX_JOYSTICKOEMVXDNAME = 260;
/// max error text length (including NULL)
public const int MAXERRORLENGTH = 256;
/// max product name length (including NULL)
public const int MAXPNAMELEN = 32;
/// Microsoft Corporation
public const ushort MM_MICROSOFT = 1;
internal const int JOYERR_BASE = 160;
internal const int MCIERR_BASE = 256;
internal const int MIDIERR_BASE = 64;
internal const int MIXERR_BASE = 1024;
internal const int MMSYSERR_BASE = 0;
internal const int TIMERR_BASE = 96;
internal const int WAVERR_BASE = 32;
///
/// The DRVCALLBACK function is the callback function used with the waveform-audio input device. This function is a
/// placeholder for the application-defined function name. The address of this function can be specified in the callback-address
/// parameter of the waveInOpen function.
///
/// Handle to the waveform-audio device associated with the callback function.
///
/// Waveform-audio input message. It can be one of the following messages.
///
///
/// Value
/// Meaning
///
/// -
/// WIM_CLOSE
/// Sent when the device is closed using the waveInClose function.
///
/// -
/// WIM_DATA
/// Sent when the device driver is finished with a data block sent using the waveInAddBuffer function.
///
/// -
/// WIM_OPEN
/// Sent when the device is opened using the waveInOpen function.
///
///
///
/// User instance data specified with waveInOpen.
/// Message parameter.
/// Message parameter.
/// This function does not return a value.
///
/// Applications should not call any system-defined functions from inside a callback function, except for
/// EnterCriticalSection, LeaveCriticalSection, midiOutLongMsg, midiOutShortMsg,
/// OutputDebugString, PostMessage, PostThreadMessage, SetEvent, timeGetSystemTime,
/// timeGetTime, timeKillEvent, and timeSetEvent. Calling other wave functions will cause deadlock.
///
// https://docs.microsoft.com/en-us/previous-versions/dd743849(v=vs.85) void CALLBACK waveInProc( HWAVEIN hwi, UINT uMsg, DWORD_PTR
// dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 );
[PInvokeData("mmsyscon.h")]
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate void DRVCALLBACK(IntPtr hdrvr, uint uMsg, IntPtr dwUser, IntPtr dwParam1, IntPtr dwParam2);
///
/// Flags used with waveOutOpen(), waveInOpen(), midiInOpen(), and midiOutOpen() to specify the type of the dwCallback parameter.
///
[PInvokeData("mmsyscom.h", MSDNShortId = "NF:mmeapi.waveInOpen")]
[Flags]
public enum CALLBACK_FLAGS : uint
{
/// No callback mechanism. This is the default setting.
CALLBACK_NULL = 0x00000000,
/// The dwCallback parameter is a window handle.
CALLBACK_WINDOW = 0x00010000,
/// The dwCallback parameter is a task handle.
CALLBACK_TASK = 0x00020000,
/// The dwCallback parameter is a callback procedure address.
CALLBACK_FUNCTION = 0x00030000,
/// The dwCallback parameter is a thread identifier.
CALLBACK_THREAD = CALLBACK_TASK,
/// The dwCallback parameter is an event handle.
CALLBACK_EVENT = 0x00050000,
}
/// Microsoft Corporation Product Identifiers
[PInvokeData("mmsyscon.h")]
public enum MMPRODID : ushort
{
/// MIDI Mapper
MM_MIDI_MAPPER = 1,
/// Wave Mapper
MM_WAVE_MAPPER = 2,
/// Sound Blaster MIDI output port
MM_SNDBLST_MIDIOUT = 3,
/// Sound Blaster MIDI input port
MM_SNDBLST_MIDIIN = 4,
/// Sound Blaster internal synthesizer
MM_SNDBLST_SYNTH = 5,
/// Sound Blaster waveform output
MM_SNDBLST_WAVEOUT = 6,
/// Sound Blaster waveform input
MM_SNDBLST_WAVEIN = 7,
/// Ad Lib-compatible synthesizer
MM_ADLIB = 9,
/// MPU401-compatible MIDI output port
MM_MPU401_MIDIOUT = 10,
/// MPU401-compatible MIDI input port
MM_MPU401_MIDIIN = 11,
/// Joystick adapter
MM_PC_JOYSTICK = 12,
}
/// Multimedia function result codes.
[PInvokeData("mmsyscon.h")]
public enum MMRESULT
{
/// no error
MMSYSERR_NOERROR = 0,
/// unspecified error
MMSYSERR_ERROR = MMSYSERR_BASE + 1,
/// Specified device identifier is out of range.
MMSYSERR_BADDEVICEID = MMSYSERR_BASE + 2,
/// driver failed enable
MMSYSERR_NOTENABLED = MMSYSERR_BASE + 3,
/// Specified resource is already allocated.
MMSYSERR_ALLOCATED = MMSYSERR_BASE + 4,
/// Specified device handle is invalid.
MMSYSERR_INVALHANDLE = MMSYSERR_BASE + 5,
/// No device driver is present.
MMSYSERR_NODRIVER = MMSYSERR_BASE + 6,
/// Unable to allocate or lock memory.
MMSYSERR_NOMEM = MMSYSERR_BASE + 7,
/// function isn't supported
MMSYSERR_NOTSUPPORTED = MMSYSERR_BASE + 8,
/// Specified error number is out of range.
MMSYSERR_BADERRNUM = MMSYSERR_BASE + 9,
/// invalid flag passed
MMSYSERR_INVALFLAG = MMSYSERR_BASE + 10,
/// invalid parameter passed
MMSYSERR_INVALPARAM = MMSYSERR_BASE + 11,
/// handle being used simultaneously on another thread (eg callback)
MMSYSERR_HANDLEBUSY = MMSYSERR_BASE + 12,
/// specified alias not found
MMSYSERR_INVALIDALIAS = MMSYSERR_BASE + 13,
/// bad registry database
MMSYSERR_BADDB = MMSYSERR_BASE + 14,
/// registry key not found
MMSYSERR_KEYNOTFOUND = MMSYSERR_BASE + 15,
/// registry read error
MMSYSERR_READERROR = MMSYSERR_BASE + 16,
/// registry write error
MMSYSERR_WRITEERROR = MMSYSERR_BASE + 17,
/// registry delete error
MMSYSERR_DELETEERROR = MMSYSERR_BASE + 18,
/// registry value not found
MMSYSERR_VALNOTFOUND = MMSYSERR_BASE + 19,
/// driver does not call DriverCallback
MMSYSERR_NODRIVERCB = MMSYSERR_BASE + 20,
/// more data to be returned
MMSYSERR_MOREDATA = MMSYSERR_BASE + 21,
/// Attempted to open with an unsupported waveform-audio format.
WAVERR_BADFORMAT = WAVERR_BASE + 0,
/// There are still buffers in the queue.
WAVERR_STILLPLAYING = WAVERR_BASE + 1,
/// The buffer pointed to by the pwh parameter hasn't been prepared.
WAVERR_UNPREPARED = WAVERR_BASE + 2,
/// device is synchronous
WAVERR_SYNC = WAVERR_BASE + 3,
/// last error in range
WAVERR_LASTERROR = WAVERR_BASE + 3,
/// header not prepared
MIDIERR_UNPREPARED = MIDIERR_BASE + 0,
/// still something playing
MIDIERR_STILLPLAYING = MIDIERR_BASE + 1,
/// no configured instruments
MIDIERR_NOMAP = MIDIERR_BASE + 2,
/// hardware is still busy
MIDIERR_NOTREADY = MIDIERR_BASE + 3,
/// port no longer connected
MIDIERR_NODEVICE = MIDIERR_BASE + 4,
/// invalid MIF
MIDIERR_INVALIDSETUP = MIDIERR_BASE + 5,
/// operation unsupported w/ open mode
MIDIERR_BADOPENMODE = MIDIERR_BASE + 6,
/// thru device 'eating' a message
MIDIERR_DONT_CONTINUE = MIDIERR_BASE + 7,
/// last error in range
MIDIERR_LASTERROR = MIDIERR_BASE + 7,
///
MIXERR_INVALLINE = MIXERR_BASE + 0,
///
MIXERR_INVALCONTROL = MIXERR_BASE + 1,
///
MIXERR_INVALVALUE = MIXERR_BASE + 2,
///
MIXERR_LASTERROR = MIXERR_BASE + 2,
}
/// Time format.
[PInvokeData("Mmsystem.h")]
public enum MMTIME_TYPE
{
/// time in milliseconds
TIME_MS = 0x0001,
/// number of wave samples
TIME_SAMPLES = 0x0002,
/// current byte offset
TIME_BYTES = 0x0004,
/// SMPTE time
TIME_SMPTE = 0x0008,
/// MIDI time
TIME_MIDI = 0x0010,
/// Ticks within MIDI stream
TIME_TICKS = 0x0020,
}
/// Makes a four character code.
/// The first character.
/// The second character.
/// The third character.
/// The fourth character.
/// The character code.
[PInvokeData("mmsyscon.h")]
public static uint MAKEFOURCC(char ch0, char ch1, char ch2, char ch3) => (byte)ch0 | ((uint)(byte)ch1 << 8) |
((uint)(byte)ch2 << 16) | ((uint)(byte)ch3 << 24);
/// Makes a four character code.
/// The four character code.
/// The character code.
[PInvokeData("mmsyscon.h")]
public static uint MAKEFOURCC(string chars)
{
if (chars is null || chars.Length != 4)
throw new ArgumentException("The character code was not a four-character string.");
return MAKEFOURCC(chars[0], chars[1], chars[2], chars[3]);
}
/// Multimedia time.
// https://docs.microsoft.com/en-us/previous-versions/dd757347(v=vs.85) typedef struct mmtime_tag { UINT wType; union { DWORD ms;
// DWORD sample; DWORD cb; DWORD ticks; struct { BYTE hour; BYTE min; BYTE sec; BYTE frame; BYTE fps; BYTE dummy; BYTE pad[2]; }
// smpte; struct { DWORD songptrpos; } midi; } u; } MMTIME, *PMMTIME, *LPMMTIME;
[PInvokeData("Mmsystem.h")]
[StructLayout(LayoutKind.Sequential)]
public struct MMTIME
{
/// Time format.
public MMTIME_TYPE wType;
/// The value.
public uint u;
/// Gets the native size of this structure.
public static uint NativeSize = unchecked((uint)Marshal.SizeOf(typeof(MMTIME)));
}
}
}