Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Search Results for "l" in [All]

odbccp32

. .

[DllImport("odbccp32.dll", SetLastError=true)]

.

Declare Function DataSources Lib "odbccp32.dll" (TODO) As TODO

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("ODBCCP32.DLL",CharSet=CharSet.Unicode, SetLastError=true)]

.

static extern bool SQLConfigDataSourceW(IntPtr hwndParent , RequestFlags fRequest, string lpszDriver, string lpszAttributes);

.

<DllImport("ODBCCP32.dll",CallingConvention:=CallingConvention.WinAPI,CharSet:=CharSet.Unicode,SetLastError:=True)> _

.

Public Shared Function SQLConfigDataSourceW(ByVal hwndParent As IntPtr, ByVal fRequest As UShort, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Boolean

.

enum RequestFlags : ushort

.

    ODBC_REMOVE_DEFAULT_DSN = 7

.
More
.

Using the value of this.Handle from within a Windows Forms application's form control will cause SQLConfigDataSource to display a dialog to the user that is pre-populated with the provided attribute values.

.

lpszAttributes:

.

Supports Name value pairs. Each value pair must be terminated by a null character.

.
More
.

One of the more popular uses for this is manipulating mdb database files. This is the file format used by Microsoft Access. You can create, compact and repair mdb files with this function.

.

The SQLConfigDataSourceW function is the Unicode variant of this function.

.

When constructing the attrubute strings be sure to put quotes around the file name. Otherwise, if there are spaces in the file name the function call will fail.

.

String.Format("CREATE_DBV4=\"{0}\" General\0", FileName);

.

Sample Code:

.

This class allows you to Create, Compact, and Repair Microsoft Access Databases.

.

    /// JetSQL is the "code name" for the SQL engine behind Microsoft Access. It's

.

    /// actually built into Windows, Microsoft Access is just a front end interface

.

    public static class JetSql

.

        private enum RequestFlags : ushort

.

            ODBC_REMOVE_DEFAULT_DSN = 7      // Remove the default data source specification section from the system information.

.

        /// A method to dynamically add DSN-names to the system. This method also

.

        /// aids with the creation, and subsequent manipulation, of Microsoft

.

        /// Access database files.

.

        /// <see cref="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqlconfigdatasource.asp"/>

.

        /// <param name="hwndParent">Parent window handle. The function will not display

.

        /// any dialog boxes if the handle is null.</param>

.

        /// <param name="fRequest">One of the OdbcConstant enum values to specify the

.

        /// type of the request (RequestFlags.ODBC_ADD_DSN to create an MDB).</param>

.

        /// <param name="lpszDriver">Driver description (usually the name of the

.

        /// associated DBMS) presented to users instead of the physical driver name.</param>

.

        /// <param name="lpszAttributes">List of attributes in the form of keyword-value

.

        /// <see cref="http://msdn.microsoft.com/library/en-us/odbc/htm/odbcconfigdsn.asp">ConfigDSN</see>

.

        /// in Chapter 22: Setup DLL Function Reference.</param>

.

        /// <returns>The function returns TRUE if it is successful, FALSE if it fails.

.

        /// If no entry exists in the system information when this function is called,

.

        /// the function returns FALSE.</returns>

.

        [DllImport("ODBCCP32.DLL", CharSet=CharSet.Unicode, SetLastError=true)]

.

        private static extern bool SQLConfigDataSourceW(UInt32 hwndParent , RequestFlags fRequest, string lpszDriver, string lpszAttributes);

.

        /// <returns>A boolean value indicating success.</returns>

.

        public static bool CompactDatabase(string DatabasePath)

.

            string attributes = String.Format("COMPACT_DB=\"{0}\" \"{0}\" General\0", DatabasePath);

.

            return SQLConfigDataSourceW(NULL_HWND, RequestFlags.ODBC_ADD_DSN, MS_ACCESS_DRIVER, attributes);

.

        /// <returns>A boolean value indicating success.</returns>

.

        public static bool CreateDatabase(string DatabasePath)

.

            string attributes = String.Format("CREATE_DB=\"{0}\" General\0", DatabasePath);

.

            return SQLConfigDataSourceW(IntPtr.Zero, RequestFlags.ODBC_ADD_DSN, MS_ACCESS_DRIVER, attributes);

.

        /// <returns>A boolean value indicating success.</returns>

.

        public static bool RepairDatabase(string DatabasePath)

.

            string attributes = String.Format("REPAIR_DB=\"{0}\" General\0", DatabasePath);

.

            return SQLConfigDataSourceW(IntPtr.Zero, RequestFlags.ODBC_ADD_DSN, MS_ACCESS_DRIVER, attributes);

.

Private Enum RequestFlags As UShort

.

    ODBC_REMOVE_DEFAULT_DSN = 7

.

<DllImport("ODBCCP32.dll",CallingConvention:=CallingConvention.WinAPI,CharSet:=CharSet.Unicode,SetLastError:=True)> _

.

Private Shared Function SQLConfigDataSourceW(ByVal hwndParent As IntPtr, ByVal fRequest As RequestFlags, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Boolean

.

Private Function CreateSystemDSN() As Boolean

.

    vAttributes &= "Server=SQLSERVERINSTANCE" & Convert.ToChar(0)

.

    If SQLConfigDataSourceW(IntPtr.Zero, RequestFlags.ODBC_ADD_SYS_DSN, "SQL Server", vAttributes) = 0 Then

.

        Messagebox.Show("Failed to create ODBC data source!!")

.

        Return False

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.
Documentation
[SQLConfigDataSource] on MSDN
. .

[DllImport("odbccp32.dll", CharSet = CharSet.Unicode, SetLastError = true)]

.

private static extern bool SQLGetInstalledDriversW(char[] lpszBuf, ushort cbufMax, out ushort pcbBufOut);

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

[DllImport("odbccp32.dll", CharSet = CharSet.Unicode, SetLastError = true)]

.

private static extern bool SQLGetInstalledDriversW(char[] lpszBuf, ushort cbufMax, out ushort pcbBufOut);

.

/// Gets the ODBC driver names from the SQLGetInstalledDrivers function.

.

/// <returns>a string array containing the ODBC driver names, if the call to SQLGetInstalledDrivers was successfull; null, otherwise.</returns>

.

public static string[] GetOdbcDriverNames()

.

     string[] odbcDriverNames = null;

.

     char[] driverNamesBuffer = new char[ushort.MaxValue];

.

     bool succeeded = SQLGetInstalledDriversW(driverNamesBuffer, ushort.MaxValue, out size);

.

     odbcDriverNames = (new string(driverNames)).Split('\0');

.
Documentation
[SQLGetInstalledDriversW] on MSDN
. .

[DllImport("odbccp32.dll", CharSet = CharSet.Unicode, SetLastError = true)]

.

private static extern bool SQLGetInstalledDriversW(char[] lpszBuf, ushort cbufMax, out ushort pcbBufOut);

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

[DllImport("odbccp32.dll", CharSet = CharSet.Unicode, SetLastError = true)]

.

private static extern bool SQLGetInstalledDriversW(char[] lpszBuf, ushort cbufMax, out ushort pcbBufOut);

.

/// Gets the ODBC driver names from the SQLGetInstalledDrivers function.

.

/// <returns>a string array containing the ODBC driver names, if the call to SQLGetInstalledDrivers was successfull; null, otherwise.</returns>

.

public static string[] GetOdbcDriverNames()

.

     string[] odbcDriverNames = null;

.

     char[] driverNamesBuffer = new char[ushort.MaxValue];

.

     bool succeeded = SQLGetInstalledDriversW(driverNamesBuffer, ushort.MaxValue, out size);

.

     odbcDriverNames = (new string(driverNames)).Split('\0');

.
Documentation
[SQLGetInstalledDriversW] on MSDN
. .
Summary
Gets a list of names of values or data corresponding to a value of the system information (MSDN ODBC Programmer's Reference). This function works similarly to the GetProfileString() Win32 API function.
.

[DllImport("odbccp32.dll", SetLastError=true)]

.

static extern int SQLGetPrivateProfileString(string lpszSection, string lpszEntry, string lpszDefault, [Out] char[] retBuffer, int cbRetBuffer, string lpszFileName);

.

Declare Function SQLGetPrivateProfileString Lib "odbccp32.dll" (TODO) As TODO

.

Sample Code:

.

    char[] value = new char[8192];

.

    SQLSetConfigMode(ConfigMode.ODBC_SYSTEM_DSN);

.

    SQLGetPrivateProfileString(dataSourceName, "Driver", "", value, value.Length, "odbc.ini");

.

    RequestFlags configMode = value[0] == '\0' ? RequestFlags.ODBC_ADD_SYS_DSN : RequestFlags.ODBC_CONFIG_SYS_DSN;

.

    // Connection string for SQLConfigDataSource must be null-

.

    // character delimited and double null-terminated

.

    string s = connStr.Replace(';', '\0');

.

    SQLConfigDataSourceW(0, configMode, MY_DRIVER_NAME_STRING, s);

.
Documentation
[SQLGetPrivateProfileString] on MSDN
. .
Summary
SQLInstallerError returns error or status information for the ODBC installer functions.
.

[DllImport("odbccp32", CharSet=CharSet.Auto)]

.

public static extern SQL_RETURN_CODE    SQLInstallerError(int iError, ref SQL_INSTALLER_ERROR_CODE pfErrorCode, StringBuilder lpszErrorMsg, int cbErrorMsgMax, ref int pcbErrorMsg);

.

<DllImport("ODBCCP32.dll", CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Auto, SetLastError:=True)> _

.

Public Shared Function SQLInstallerError(ByVal iError As Integer, ByRef pfErrorCode As Integer, ByVal lpszErrorMsg As StringBuilder, ByVal cbErrorMsgMax As Integer, ByRef pcbErrorMsg As Integer) As SQL_RETURN_CODE

.

public enum SQL_RETURN_CODE : short

.

    SQL_ERROR            = -1,

.

    SQL_INVALID_HANDLE        = -2,

.

    SQL_SUCCESS        = 0,

.

    SQL_SUCCESS_WITH_INFO    = 1,

.

    SQL_STILL_EXECUTING    = 2,

.

    SQL_NEED_DATA        = 99,

.

    SQL_NO_DATA        = 100

.

public enum SQL_INSTALLER_ERROR_CODE : uint

.

     ODBC_ERROR_GENERAL_ERR = 1,

.

     ODBC_ERROR_INVALID_BUFF_LEN = 2,

.

     ODBC_ERROR_INVALID_HWND = 3,

.

     ODBC_ERROR_INVALID_STR = 4,

.

     ODBC_ERROR_INVALID_REQUEST_TYPE = 5,

.

     ODBC_ERROR_INVALID_NAME = 7,

.

     ODBC_ERROR_INVALID_KEYWORD_VALUE = 8,

.

     ODBC_ERROR_INVALID_DSN = 9,

.

     ODBC_ERROR_INVALID_INF = 10,

.

     ODBC_ERROR_REQUEST_FAILED = 11,

.

     ODBC_ERROR_INVALID_PATH = 12,

.

     ODBC_ERROR_LOAD_LIB_FAILED = 13,

.

     ODBC_ERROR_INVALID_PARAM_SEQUENCE = 14,

.

     ODBC_ERROR_INVALID_LOG_FILE = 15,

.

     ODBC_ERROR_USER_CANCELED = 16,

.

     ODBC_ERROR_USAGE_UPDATE_FAILED = 17,

.

     ODBC_ERROR_CREATE_DSN_FAILED = 18,

.

     ODBC_ERROR_WRITING_SYSINFO_FAILED = 19,

.

     ODBC_ERROR_REMOVE_DSN_FAILED = 20,

.

Enum RequestFlags As Integer

.

  ODBC_REMOVE_DEFAULT_DSN = 7

.
More
.

Each time a new installer function is called the error queue is flushed. This means that you can only retrieve errors from the last installer function call, and not from ones before it.

.

SQLInstallerError does not post error values for itself. SQLInstallerError returns SQL_NO_DATA when it is unable to retrieve any error information (in which case pfErrorCode is undefined). If SQLInstallerError cannot access error values for any reason that would normally return SQL_ERROR, SQLInstallerError returns SQL_ERROR but does not post any error values. If either the lpszErrorMsg argument is NULL or the cbErrorMsgMax is less than or equal to 0, this function returns SQL_ERROR. If the buffer for the error message is too short, SQLInstallerError returns SQL_SUCCESS_WITH_INFO and returns the correct pfErrorCode value for SQLInstallerError.

.

Please add some!

.

Sample Code:

.

StringBuilder         errorMesg        = new StringBuilder( 512 ) ;

.

SQL_INSTALLER_ERROR_CODE  errorCode        = 0 ;

.

SQL_RETURN_CODE retCode = SQLInstallerError(1, ref errorCode, errorMesg, errorMesg.Capacity, ref resizeErrorMesg );

.

VB.NET Sample Code

.

Dim errorMsg As New StringBuilder(512)

.

Dim retCode As SQL_RETURN_CODE = SQLInstallerError(1, errorCode, errorMsg, errorMsg.Capacity, resizeErrorMesg)

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.
Documentation
[SQLInstallerError] on MSDN
. .
Summary
Sets the configuration mode that indicates where the Odbc.ini entry listing DSN values is in the system information (MSDN ODBC Programmer's Reference).
.

[DllImport("odbccp32.dll", SetLastError=true)]

.

static extern bool SQLSetConfigMode(ConfigMode configMode);

.

Declare Function SQLSetConfigMode Lib "odbccp32.dll" (TODO) As TODO

.

Sample Code:

.

    char[] value = new char[8192];

.

    SQLSetConfigMode(ConfigMode.ODBC_SYSTEM_DSN);

.

    SQLGetPrivateProfileString(dataSourceName, "Driver", "", value, value.Length, "odbc.ini");

.

    RequestFlags configMode = value[0] == '\0' ? RequestFlags.ODBC_ADD_SYS_DSN : RequestFlags.ODBC_CONFIG_SYS_DSN;

.

    // Connection string for SQLConfigDataSource must be null-

.

    // character delimited and double null-terminated

.

    string s = connStr.Replace(';', '\0');

.

    SQLConfigDataSourceW(0, configMode, MY_DRIVER_NAME_STRING, s);

.
Documentation
[SQLSetConfigMode] on MSDN
.
Description
odbccp32.dll
.
Title
odbccp32.dll
.
Import
credui,advapi32,gdi32,kernel32,ole32,shell32,user32,glossary,coredll,rasapi32,mpr,netapi32,uxtheme,avifil32,aygshell,winscard,crypt32,secur32,wtsapi32,shlwapi,winspool,oleacc,rapi,oleaut32,winfax,odbc32,msi,cards,powrprof,urlmon,xolehlp,twain_32,winmm,wininet,comdlg32,imm32,ntdsapi,gdiplus,Constants,Delegates,Enums,Interfaces,Structures

winmm

. .

[DllImport("winmm.dll")]

.

static extern Int32 mciGetErrorString(Int32 errorCode, StringBuilder errorText, Int32 errorTextSize);

.

<DllImport("winmm.dll")> _

.

Private Shared Function mciGetErrorString(ByVal dwError As Integer, ByVal lpstrBuffer As System.Text.StringBuilder, ByVal uLength As Integer) As Integer

.

Public Declare Auto Function mciGetErrorString Lib "winmm.dll" (ByVal errorCode As Integer, ByRef errorText As StringBuilder, ByVal errorTextSize As Integer) As Integer

.

Please add some!

.

Sample Code:

.

Please add some!

.

Alternative Managed API:

.

Do you know one? Please contribute it!

. .

[DllImport("winmm.dll")]

.

static extern Int32 mciSendString(string command, StringBuilder buffer, int bufferSize, IntPtr hwndCallback);

.

<DllImport("winmm.dll")> _

.

Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer

.

Declare Ansi Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal command As String, ByRef buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hWndCallback As IntPtr) As Integer

.

Please add some!

.

Sample Code

.

public void OpenCD()

.

    StringBuilder returnstring = new StringBuilder();

.

// Open Media File

.

string sCommand = "open \"" + strFilePath + "\" type mpegvideo alias MediaFile";

.

mciSendString(sCommand, null, 0, 0);

.

// Play the Media File

.

sCommand = "play MediaFile notify";

.

// _frmObject is your form that will handle the notification messages

.

mciSendString(sCommand, null, 0, _frmObject.Handle.ToInt64());

.

// Declare the notify constant

.

public const int MM_MCINOTIFY = 953;

.

        // The file is done playing, do whatever

.

Or try something like that:

.

[DllImport("winmm.dll")]

.

static extern Int32 mciSendString(string command, string buffer, int bufferSize, IntPtr hwndCallback);

.

private void CloseCdCommand()

.

     mciSendString("set CDAudio door closed", rt, 127, IntPtr.Zero);

.

Public Sub OpenCDDoor()

.

     Dim returnstring As StringBuilder = New StringBuilder()

.

' Declare the notify constant

.

Public Const MM_MCINOTIFY As Integer = 953

.

' Open and play a media file

.

Public Sub OpenMediaFile(ByVal strFilePath As String)

.

     ' Open the media file

.

     Dim sCommand As String = "open """ + strFilePath + """ type waveaudio alias MediaFile"

.

     sCommand = "play MediaFile notify"

.

     mciSendString(sCommand, Nothing, 0, Me.Handle.ToInt64())

.

' Override the WndProc function which is called when the play function ends

.

     ' The file is done playing, do whatever is necessary at this point

.

     MsgBox("Done playing.")

.

Alternative Managed API:

.

Do you know one? Please contribute it!

. . .

[DllImport("winmm.dll")]

.

Declare Function midiConnect Lib "winmm.dll" (TODO) As TODO

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

UInt32 Connect(IntPtr midiInputHandle, IntPtr midiOutputHandle)

.

     return midiConnect(midiInputHandle, midiOutputHandle, IntPtr.Zero);

. . .

[DllImport("winmm.dll")]

.

Declare Function midiDisconnect Lib "winmm.dll" (TODO) As TODO

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

UInt32 Disconnect(IntPtr midiInputHandle, IntPtr midiOutputHandle)

.

     return midiDisconnect(midiInputHandle, midiOutputHandle, IntPtr.Zero);

. .

    [StructLayout(LayoutKind.Sequential)]

.

    internal struct MIDIHDR

.

    public IntPtr data;

.

    public uint bufferLength;

.

    public uint bytesRecorded;

.

    public IntPtr user;

.

    public uint flags;

.

    public IntPtr next;

.

    public IntPtr reserved;

.

    public uint offset;

.

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]

.

    public IntPtr[] reservedArray;

.

Declare Function MIDIHDR Lib "winmm.dll" (TODO) As TODO

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .
Summary
The midiInClose function closes the specified MIDI input device
.

[DllImport("winmm.dll", SetLastError = true)]

.

    private static extern uint midiInClose(IntPtr hMidiIn);

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Uses an IntPtr for the (opaque) midi handle

.

Sample Code:

.

Please add some!

.
Documentation
[midiInClose] on MSDN
. .
Summary
The midiInGetDevCaps function determines the capabilities of a specified MIDI input device.
.

    [DllImport("winmm.dll", SetLastError = true)]

.

    private static extern MMRESULT midiInGetDevCaps(UIntPtr uDeviceID, ref MIDIINCAPS caps, uint cbMidiInCaps);

.

MMRESULT

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Use (uint)Marshal.SizeOf(typeof(MIDIINCAPS)) for cbMidiInCaps.

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll", SetLastError = true)]

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll", SetLastError=true)]

.

static extern uint midiInOpen(out IntPtr lphMidiIn, uint uDeviceID, IntPtr dwCallback, IntPtr dwInstance, uint dwFlags);

.

Declare Function midiInOpen Lib "winmm.dll" (TODO) As TODO

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

    [DllImport("winmm.dll", SetLastError = true)]

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Passes the (opaque) midi handle as an IntPtr

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll", SetLastError = true)]

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

This is using an IntPtr for the (opaque) midi handle.

.

Please add some!

.

Sample Code:

.

Please add some!

. .
Summary
The MIDIOUTCAPS structure describes the capabilities of a MIDI output device.
.

    [StructLayout(LayoutKind.Sequential)]

.

    public ushort wMid;

.

    public ushort wPid;

.

    public uint vDriverVersion;     //MMVERSION

.

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst= 32)]

.

    public string szPname;

.

    public ushort wTechnology;

.

    public ushort wVoices;

.

    public ushort wNotes;

.

    public ushort wChannelMask;

.

    public uint dwSupport;

.

    // values for wTechnology field of MIDIOUTCAPS structure

.

    private const ushort MOD_SYNTH = 2;        // generic internal synth

.

    private const ushort MOD_SQSYNTH = 3;      // square wave internal synth

.

    private const ushort MOD_FMSYNTH = 4;      // FM internal synth

.

    private const ushort MOD_WAVETABLE = 6;    // hardware wavetable synth

.

    // flags for dwSupport field of MIDIOUTCAPS structure

.

    private const uint MIDICAPS_VOLUME = 1;      // supports volume control

.

    private const uint MIDICAPS_LRVOLUME = 2;    // separate left-right volume control

.

    private const uint MIDICAPS_STREAM = 8;      // driver supports midiStreamOut directly

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

.

This is sample Code

.

int result = midiOutGetDevCaps(deviceID, ref outCaps, Marshal.SizeOf(outCaps));

. .

[DllImport("winmm.dll")]

.

static extern uint midiOutClose(IntPtr hMidiOut);

.

Declare Function midiOutClose Lib "winmm.dll" (ByRef phMidiOut As IntPtr) As Uinteger

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

.
Documentation
[midiOutClose] on MSDN
. .
Summary
The midiOutGetDevCaps function queries a specified MIDI output device to determine its capabilities.
.

[DllImport("winmm.dll", SetLastError = true)]

.

public static extern MMRESULT midiOutGetDevCaps(UIntPtr uDeviceID, ref MIDIOUTCAPS lpMidiOutCaps, uint cbMidiOutCaps);

.

MMRESULT

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Use (uint)Marshal.SizeOf(typeof(MIDIOUTCAPS)) for cbMidiOutCaps.

.

Sample Code:

.

    [DllImport("winmm.dll", SetLastError = true)]

.

    [DllImport("Winmm.dll")]

.

    [StructLayout(LayoutKind.Sequential)]

.

        public ushort wMid;

.

        public ushort wPid;

.

        public uint vDriverVersion;

.

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]

.

        public string szPname;

.

        public ushort wTechnology;

.

        public ushort wVoices;

.

        public ushort wNotes;

.

        public ushort wChannelMask;

.

        public uint dwSupport;

.

        midiOutGetDevCaps((UIntPtr) x, out caps, (uint)Marshal.SizeOf(typeof(MIDIOUTCAPS)));

. . .
Summary
Retrieves a textual description for an error identified by the specified error code.
.

[DllImport("winmm.dll")]

.

static extern uint midiOutGetErrorText(uint mmrError, StringBuilder pszText, uint cchText);

.

Declare Function midiOutGetErrorText Lib "winmm.dll" (TODO) As TODO

.

const uint MAXERRORLENGTH = 256;

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

  public string GetErrorText(uint mmrError)

.

    StringBuilder sb = new StringBuilder((int)MAXERRORLENGTH);

.

    uint uiMMResult = midiOutGetErrorText(mmrError, sb, MAXERRORLENGTH + 1);

.

    if (uiMMResult != MMSYSERR_NOERROR)

.

      throw new Exception(string.Format("Failed to get error text for result {0}.", mmrError));

. .

[DllImport("winmm.dll", SetLastError=true)]

.

Declare Function midiOutGetNumDevs Lib "winmm.dll" () As uint

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

    [DllImport("winmm.dll")]

.

    static extern uint midiOutOpen(out IntPtr lphMidiOut, uint uDeviceID, IntPtr dwCallback, IntPtr dwInstance, uint dwFlags);

.

    <DllImport("winmm.dll")> Shared Function midiOutOpen(ByRef lphMidiOut As IntPtr, ByVal uDeviceID As UInteger, ByVal dwCallback As IntPtr, ByVal dwInstance As IntPtr, ByVal dwFlags As UInteger) As UInteger

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

The device should be disposed with midiOutClose when not needed anymore.

.

Please add some!

.

Sample Code:

.

//hmidi is now a valid pointer to MIDI device 0.

. .

[DllImport("winmm.dll")]

.

Declare Function midiOutShortMsg Lib "winmm.dll" (hMidiOut As Intptr,dwMsg As UInt32) As UInt32

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

//[0] = status byte containing voice message and channel

.

data[0] = 0xC0;//change instrument, channel 0

.

data[0] = 0x90;//note on, channel 0

.

data[2] = 100;//velocity

. .

[DllImport("winmm.dll")]

.

extern static Int32 midiStreamClose(IntPtr hMidiStream);

.

Public Declare Function midiStreamClose Lib "winmm.dll" (ByVal hMidiStream As IntPtr) As Integer

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

.
Documentation
[midiStreamClose] on MSDN
. .

[DllImport("winmm.dll")]

.

extern static Int32 midiStreamOpen(ref IntPtr hMidiStream, ref Int32 puDeviceID, Int32 cMidi, IntPtr dwCallback, IntPtr dwInstance, Int32 fdwOpen);

.

Public Declare Function midiStreamOpen Lib "winmm.dll" (ByVal hMidiStream As IntPtr, ByVal puDeviceId As IntPtr, ByVal cMidi As Integer, ByVal dwCallback As IntPtr, ByVal dwInstance As IntPtr, ByVal fdwOpen As Integer) As Integer

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll")]

.

static extern Int32 midiStreamOut(IntPtr hMidiStream, MIDIHDR lpMidiHdr, uint cbMidiHdr);

.

Declare Function midiStreamOut Lib "winmm.dll" (ByVal hMidiStream As IntPtr, ByVal lpMidiHdr As MIDIHDR, ByVal cbMidiHdr As UInteger) As Integer

.

     string lpdata;

.

     int dwBufferLength;

.

     int dwFlags;

.

     MIDIHDR lpNext;

.

     Dim lpData As String

.

     Dim dwBufferLength As Integer

.

     Dim dwFlags As Integer

.

     Dim lpNext As Object

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll")]

.

Declare Function midiStreamPause Lib "winmm.dll" (ByVal hMidiStream As IntPtr) As Integer

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll")]

.

Declare Function midiStreamPosition Lib "winmm.dll" (ByVal hms As IntPtr, ByVal pmmt As MMTIME, ByVal cbmmt As UInteger) As Integer

.

     Dim sample As Integer

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll")]

.

Declare Function midiStreamProperty Lib "winmm.dll" (TODO) As TODO

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll")]

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll")]

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

DllImport("winmm.dll")]

.

static extern Int32 mixerClose(IntPtr hmx);

.

Declare Function mixerClose Lib "winmm.dll" (ByVal hmx As IntPtr) As Integer

.

Please add some!

.

Sample Code:

.

Please add some!

.

Alternative Managed API:

.

The ManagedWindowsApi project (http://mwinapi.sourceforge.net) provides a Mixer control.

.
Documentation
[mixerClose] on MSDN
. .
Summary
Flags for mixer... functions.
.

    public enum MIXER_FLAGS

.

      MIXER_OBJECTF_HANDLE = unchecked((int)0x80000000),

.

      MIXER_OBJECTF_HMIXER = MIXER_OBJECTF_MIXER | MIXER_OBJECTF_HANDLE,

.

      MIXER_OBJECTF_HWAVEOUT = MIXER_OBJECTF_WAVEOUT | MIXER_OBJECTF_HANDLE,

.

      MIXER_OBJECTF_HWAVEIN = MIXER_OBJECTF_WAVEIN | MIXER_OBJECTF_HANDLE,

.

      MIXER_OBJECTF_HMIDIOUT = MIXER_OBJECTF_MIDIOUT | MIXER_OBJECTF_HANDLE,

.

      MIXER_OBJECTF_HMIDIIN = MIXER_OBJECTF_MIDIIN | MIXER_OBJECTF_HANDLE,

.

      MIXER_GETCONTROLDETAILSF_VALUE = 0,

.

      MIXER_SETCONTROLDETAILSF_VALUE = 0,

.

      MIXER_GETCONTROLDETAILSF_LISTTEXT = 1,

.

      MIXER_SETCONTROLDETAILSF_LISTTEXT = 1,

.

      MIXER_GETCONTROLDETAILSF_QUERYMASK = 0xF,

.

      MIXER_SETCONTROLDETAILSF_QUERYMASK = 0xF,

.

      MIXER_GETLINECONTROLSF_QUERYMASK = 0xF,

.

      MIXER_GETLINECONTROLSF_ALL = 0,

.

      MIXER_GETLINECONTROLSF_ONEBYID = 1,

.

      MIXER_GETLINECONTROLSF_ONEBYTYPE = 2,

.

      MIXER_GETLINEINFOF_DESTINATION = 0,

.

      MIXER_GETLINEINFOF_SOURCE = 1,

.

      MIXER_GETLINEINFOF_LINEID = 2,

.

      MIXER_GETLINEINFOF_COMPONENTTYPE = 3,

.

      MIXER_GETLINEINFOF_TARGETTYPE = 4,

.

      MIXER_GETLINEINFOF_QUERYMASK = 0xF,

.

<Flags()> _

.

Enum MixerFlags

.

  MIXER_GETLINEINFOF_DESTINATION = 0

.

  MIXER_GETLINEINFOF_SOURCE = 1

.

  MIXER_GETLINEINFOF_LINEID = 2

.

  MIXER_GETLINEINFOF_COMPONENTTYPE = 3

.

  MIXER_GETLINEINFOF_TARGETTYPE = 4

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

This enumeration is not yet complete. Many functions use other flags that are not included in this list. Please help to integrate it.

.

Please add some!

.

Sample Code:

.

Please add some!

.
Documentation
[MixerFlags] on MSDN
. .

[DllImport("winmm.dll")]

.

static extern Int32 mixerGetControlDetails(IntPtr hmxobj,

.

   ref MixerControlDetails pmxcd, UInt32 fdwDetailsmixer);

.

Declare Function mixerGetControlDetails Lib "winmm.dll" (<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer

.

The winmm dll may not execute properly on 64-bit systems. Consequently, the StructLayout must be Sequential, with CharSet = Ansi, and Pack = 4. This particular type has some special layout considerations (the c union keyword) which typically means developers would use the explicit layout. However, the explicit layout breaks down on 64-bit systems for any type with an IntPtr in the type. Consequently, the C# types have been redesigned to use Sequential layout so that they will automatically adjust to 64-bit systems. This means private fields with public properties which perform the gunky work of making it look like there is a union.

.

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]

.

public struct MIXERCONTROLDETAILS

.

     private UInt32 dwControlID;

.

     private UInt32 cChannels;

.

//     private UInt32 cMultipleItems; //Unioned with hwndOwner /* if _MULTIPLE, the number of items per channel */

.

     private UInt32 cbDetails;

.

     private IntPtr paDetails;

.

     /// <summary>size in bytes of MIXERCONTROLDETAILS</summary>

.

     public UInt32 StructSize

.

        set { this.cbStruct = value; }

.

     /// <summary>control id to get/set details on</summary>

.

     public UInt32 ControlID

.

        get { return this.dwControlID; }

.

        set { this.dwControlID = value; }

.

     /// <summary>number of channels in paDetails array</summary>

.

     public UInt32 Channels

.

        get { return this.cChannels; }

.

        set { this.cChannels = value; }

.

     /// <summary>for MIXER_SETCONTROLDETAILSF_CUSTOM</summary>

.

     public IntPtr OwnerHandle

.

        set { this.hwndOwner = value; }

.

     /// <summary>if _MULTIPLE, the number of items per channel</summary>

.

     public UInt32 MultipleItems

.

        set { this.hwndOwner = (IntPtr)value; }

.

     /// <summary>size of _one_ details_XX struct</summary>

.

     public UInt32 DetailsItemSize

.

        get { return this.cbDetails; }

.

        set { this.cbDetails = value; }

.

     /// <summary>pointer to array of details_XX structs</summary>

.

     public IntPtr DetailsPointer

.

        get { return this.paDetails; }

.

        set { this.paDetails = value; }

.

The fdwDetailsmixer parameter can be composed constants from two distinct enumerations, one of which is used frequently in the winmm library, and the other constant is only used with this method. Consequently, you should wrap up the method definition so that it is easier to use, and more consistent. In the following example, the actual extern is private, while the public static method lists both enums to callers.

.

[DllImport("winmm.dll", CharSet = CharSet.Unicode)]

.

private static extern Int32 mixerGetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, uint fdwDetails);

.

public static Int32 mixerGetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, MIXER_OBJECTF fdwDetails, MIXER_GETCONTROLDETAILSF getControlDetails)

.

     uint flags = ((uint)fdwDetails | (uint)getControlDetails);

.

     return mixerGetControlDetails(hmxobj, ref pmxcd, flags);

.

public enum MIXER_OBJECTF : uint

.

     HANDLE   = 0x80000000u,

.

     HMIXER   = (HANDLE | MIXER),

.

     HWAVEOUT = (HANDLE | WAVEOUT),

.

     HWAVEIN  = (HANDLE | WAVEIN),

.

     HMIDIOUT = (HANDLE | MIDIOUT),

.

     HMIDIIN  = (HANDLE | MIDIIN),

.

public enum MIXER_GETCONTROLDETAILSF : uint

.

     VALUE      = 0x00000000u,

.

     LISTTEXT   = 0x00000001u,

.

Sample Code:

.

Please add some!

.

Alternative Managed API:

.

The ManagedWindowsApi project (http://mwinapi.sourceforge.net) provides a Mixer control.

.
Documentation
[mixerGetControlDetails] on MSDN
. .
Summary
The mixerGetDevCaps function queries a specified mixer device to determine its capabilities.
.

   [DllImport("winmm.dll", EntryPoint="mixerGetDevCaps", SetLastError=true)]

.

   <DllImport("winmm.dll", EntryPoint:="mixerGetDevCaps", SetLastError:=True)> _

.

   Private Shared Function MixerGetDevCaps(ByVal mixerId As Integer, ByRef mixerCaps As MixerCaps, ByVal mixerCapsSize As Integer) As UInteger

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

   namespace ConsoleApplication3

.

       class Program

.

       [DllImport("winmm.dll", EntryPoint = "mixerGetNumDevs")]

.

       [DllImport("winmm.dll", EntryPoint = "mixerGetDevCaps", SetLastError = true)]

.

       [StructLayout(LayoutKind.Sequential)]

.

           public ushort ManufacturerID;

.

           public ushort ProductId;

.

           public int Version;

.

           [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]

.

           public String ProductName;

.

           public uint Support;

.

           public uint Destinations;

.

           public override String ToString()

.

           uint result = MixerGetDevCaps(mixerId, ref caps, Marshal.SizeOf(caps));

.

           Console.WriteLine(caps.ToString());        

.

           Console.ReadKey();

. .
Summary
The mixerGetID function retrieves the device identifier for a mixer device associated with a specified device handle.
.

[DllImport("winmm.dll", SetLastError=true)]

.

<DllImport("winmm.dll")> _

.

Shared Function mixerGetID(<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, ByRef puMxId As UInteger, ByVal fdwId As MixerFlags) As MMRESULT

.

MMRESULT

.

MixerFlags

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll")]

.

static extern Int32 mixerGetLineControls(IntPtr hmxobj,

.

   ref MIXERLINECONTROLS pmxlc, UInt32 fdwControls);

.

Declare Function mixerGetLineControls Lib "winmm.dll" (hmxobj As IntPtr, _

.

   ByRef pmxlc As MIXERLINECONTROLS, fdwControls As Integer) As Integer

.

MIXERLINECONTROLS

.

Please add some!

.

The fdwControls parameter can be composed constants from two distinct enumerations, one of which is used frequently in the winmm library, and the other constant is only used with this method. Consequently, you should wrap up the method definition so that it is easier to use, and more consistent. In the following example, the actual extern is private, while the public static method lists both enums to callers.

.

[DllImport("winmm.dll")]

.

private static extern Int32 mixerGetLineControls(IntPtr hmxobj, ref MIXERLINECONTROLS pmxlc, uint fdwControls);

.

public static Int32 mixerGetLineControls(IntPtr hmxobj, ref MIXERLINECONTROLS pmxlc, MIXER_OBJECTF mixerFlags, MIXER_GETLINECONTROLSF controlsFlags)

.

     uint flags = ((uint)mixerFlags | (uint)controlsFlags);

.

     return mixerGetLineControls(hmxobj, ref pmxlc, flags);

.

public enum MIXER_OBJECTF : uint

.

     HANDLE   = 0x80000000u,

.

     HMIXER   = (HANDLE | MIXER),

.

     HWAVEOUT = (HANDLE | WAVEOUT),

.

     HWAVEIN  = (HANDLE | WAVEIN),

.

     HMIDIOUT = (HANDLE | MIDIOUT),

.

     HMIDIIN  = (HANDLE | MIDIIN),

.

public enum MIXER_GETLINECONTROLSF : uint

.

     ALL      = 0x00000000u,

.

Sample Code:

.

Please add some!

.

Alternative Managed API:

.

The ManagedWindowsApi project (http://mwinapi.sourceforge.net) provides a Mixer control.

.
Documentation
[mixerGetLineControls] on MSDN
. .

[DllImport("winmm.dll")]

.

static extern Int32 mixerGetLineInfo(IntPtr hmxobj,

.

   ref MIXERLINE pmxl, UInt32 fdwInfo);

.

  <DllImport("winmm.dll")> _

.

Shared Function mixerGetLineInfo(<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As MixerFlags) As MMRESULT

.

MIXERLINE

.

MMRESULT

.

MixerFlags

.

The fdwInfo parameter can be composed constants from two distinct enumerations, one of which is used frequently in the winmm library, and the other constant is only used with this method. Consequently, you should wrap up the method definition so that it is easier to use, and more consistent. In the following example, the actual extern is private, while the public static method lists both enums to callers.

.

[DllImport("winmm.dll")]

.

private static extern Int32 mixerGetLineInfo(IntPtr hmxobj, ref MIXERLINE pmxl, uint fdwInfo);

.

public static Int32 mixerGetLineInfo(IntPtr hmxobj, ref MIXERLINE pmxl, MIXER_OBJECTF fdwInfo, MIXER_GETLINEINFOF fieldToFollow)

.

     uint flags = ((uint)fdwInfo | (uint)fieldToFollow);

.

     return mixerGetLineInfo(hmxobj, ref pmxl, flags);

.

public enum MIXER_OBJECTF : uint

.

     HANDLE   = 0x80000000u,

.

     HMIXER   = (HANDLE | MIXER),

.

     HWAVEOUT = (HANDLE | WAVEOUT),

.

     HWAVEIN  = (HANDLE | WAVEIN),

.

     HMIDIOUT = (HANDLE | MIDIOUT),

.

     HMIDIIN  = (HANDLE | MIDIIN),

.

public enum MIXER_GETLINEINFOF : uint

.

     LINEID       = 0x00000002u,

.

Sample Code:

.

Please add some!

.

Alternative Managed API:

.

The ManagedWindowsApi project (http://mwinapi.sourceforge.net) provides a Mixer control.

.
Documentation
[mixerGetLineInfo] on MSDN
. .

[DllImport("winmm.dll", SetLastError=true)]

.

Declare Function mixerGetNumDevs Lib "winmm.dll" () As UInt32

.

Please add some!

.

Sample Code:

.

  Console.WriteLine("Number of mixers present: {0}", mixerGetNumDevs());

.

Alternative Managed API:

.

Do you know one? Please contribute it!

. .

[DllImport("winmm.dll", SetLastError=true)]

.

Public Declare Function mixerGetNumDevs Lib "winmm.dll" () As Integer

.

Please add some!

.

Sample Code:

.

Alternative Managed API:

.

The ManagedWindowsApi project (http://mwinapi.sourceforge.net) provides a Mixer control.

. .

[DllImport("winmm.dll")]

.

   IntPtr dwCallback, IntPtr dwInstance, UInt32 fdwOpen);

.

Declare Function mixerOpen Lib "winmm.dll" (ByRef phmx As IntPtr, ByVal pMxId As UInteger, ByVal dwCallback As IntPtr, ByVal dwInstance As IntPtr, ByVal fdwOpen As UInteger) As Integer

.

Please add some!

.

Sample Code:

.

Please add some!

.

Alternative Managed API:

.

The ManagedWindowsApi project (http://mwinapi.sourceforge.net) provides a Mixer control.

. .

[DllImport("winmm.dll")]

.

static extern Int32 mixerSetControlDetails(IntPtr hmxobj,

.

   ref MixerControlDetails pmxcd, UInt32 fdwDetails);

.

Declare Function mixerSetControlDetails Lib "winmm.dll" (ByVal hmxobj As IntPtr, ByVal pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer

.

The winmm dll may not execute properly on 64-bit systems. Consequently, the StructLayout must be Sequential, with CharSet = Ansi, and Pack = 4. This particular type has some special layout considerations (the c union keyword) which typically means developers would use the explicit layout. However, the explicit layout breaks down on 64-bit systems for any type with an IntPtr in the type. Consequently, the C# types have been redesigned to use Sequential layout so that they will automatically adjust to 64-bit systems. This means private fields with public properties which perform the gunky work of making it look like there is a union.

.

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]

.

public struct MIXERCONTROL

.

     private UInt32 dwControlID;

.

     private UInt32 dwControlType;

.

     private UInt32 fdwControl;

.

     private UInt32 cMultipleItems;

.

     [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MixerXPNative.MIXER_SHORT_NAME_CHARS)]

.

     [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MixerXPNative.MIXER_LONG_NAME_CHARS)]

.

     public MIXERCONTROL_BOUNDS Bounds;

.

     public MIXERCONTROL_METRICS Metrics;

.

     /// <summary>size in bytes of <see cref="MIXERCONTROL">MIXERCONTROL</see></summary>

.

     public UInt32 StructSize

.

        set { this.cbStruct = value; }

.

     public UInt32 ControlID

.

        get { return this.dwControlID; }

.

        set { this.dwControlID = value; }

.

     /// <summary>MIXERCONTROL_CONTROLTYPE_xxx</summary>

.

     public MIXERCONTROL_CONTROLTYPE ControlType

.

        get { return (MIXERCONTROL_CONTROLTYPE)this.dwControlType; }

.

        set { this.dwControlType = (UInt32)value; }

.

     /// <summary>MIXERCONTROL_CONTROLF_xxx</summary>

.

     public MIXERCONTROL_CONTROLF Control

.

        get { return (MIXERCONTROL_CONTROLF)this.fdwControl; }

.

        set { this.fdwControl = (uint)value; }

.

     /// <summary>if MIXERCONTROL_CONTROLF_MULTIPLE set</summary>

.

     public UInt32 MultipleItems

.

        get { return this.cMultipleItems; }

.

        set { this.cMultipleItems = value; }

.

     public String ShortName

.

        set { this.szShortName = value; }

.

     public String Name

.

        set { this.szName = value; }

.

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]

.

public struct MIXERCONTROL_BOUNDS

.

     private Int32 lMinimum;

.

     private Int32 lMaximum;

.

     //public uint dwMinimum; // Unioned with lMinimum

.

     //public uint dwMaximum; // Unioned with lMaximum

.

     //public uint dwReserved1; // Unioned with lMinimum

.

     //public uint dwReserved2; // Unioned with lMaximum

.

     /// <summary>signed minimum for this control</summary>

.

     public Int32 Minimum

.

        get { return this.lMinimum; }

.

        set { this.lMinimum = value; }

.

     /// <summary>signed maximum for this control</summary>

.

     public Int32 Maximum

.

        get { return this.lMaximum; }

.

        set { this.lMaximum = value; }

.

     /// <summary>unsigned minimum for this control</summary>

.

     public UInt32 UnsignedMinimum

.

        get { return (uint)this.lMinimum; }//TODO: something different

.

        set { this.lMinimum = (int)value; }

.

     /// <summary>unsigned maximum for this control</summary>

.

     public UInt32 UnsignedMaximum

.

        get { return (uint)this.lMaximum; }//TODO: something different

.

        set { this.lMaximum = (int)value; }

.

     public UInt32 Reserved1

.

        get { return (uint)this.lMinimum; }//TODO: something different

.

        set { this.lMinimum = (int)value; }

.

     public UInt32 Reserved2

.

        get { return (uint)this.lMaximum; }//TODO: something different

.

        set { this.lMaximum = (int)value; }

.

     public UInt32 Reserved3

.

        set { this.dwReserved3 = value; }

.

     public UInt32 Reserved4

.

        set { this.dwReserved4 = value; }

.

     public UInt32 Reserved5

.

        set { this.dwReserved5 = value; }

.

     public UInt32 Reserved6

.

        set { this.dwReserved6 = value; }

.

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]

.

public struct MIXERCONTROL_METRICS

.

     public UInt32 Steps

.

        set { this.cSteps = value; }

.

     public UInt32 CustomData

.

        set { this.cSteps = value; }

.

     public UInt32 Reserved1

.

        set { this.cSteps = value; }

.

     public UInt32 Reserved2

.

        set { this.dwReserved2 = value; }

.

     public UInt32 Reserved3

.

        set { this.dwReserved3 = value; }

.

     public UInt32 Reserved4

.

        set { this.dwReserved4 = value; }

.

     public UInt32 Reserved5

.

        set { this.dwReserved5 = value; }

.

     public UInt32 Reserved6

.

        set { this.dwReserved6 = value; }

.

Structure MIXERCONTROLDETAILS

.

     Dim dwControlID As Integer

.

     Dim cChannels As Integer

.

     Dim cMultipleItems As Integer

.

     Dim cbDetails As Integer

.

     Dim paDeatails As IntPtr

.

The fdwDetails parameter can be composed constants from two distinct enumerations, one of which is used frequently in the winmm library, and the other constant is only used with this method. Consequently, you should wrap up the method definition so that it is easier to use, and more consistent. In the following example, the actual extern is private, while the public static method lists both enums to callers.

.

[DllImport("winmm.dll", CharSet = CharSet.Unicode)]

.

private static extern Int32 mixerSetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, uint fdwDetails);

.

public static Int32 mixerSetControlDetails(IntPtr hmxobj, ref MIXERCONTROLDETAILS pmxcd, MIXER_OBJECTF fdwDetails, MIXER_SETCONTROLDETAILSF setControlDetails)

.

     uint flags = ((uint)fdwDetails | (uint)setControlDetails);

.

     return mixerSetControlDetails(hmxobj, ref pmxcd, flags);

.

public enum MIXER_OBJECTF : uint

.

     HANDLE   = 0x80000000u,

.

     HMIXER   = (HANDLE | MIXER),

.

     HWAVEOUT = (HANDLE | WAVEOUT),

.

     HWAVEIN  = (HANDLE | WAVEIN),

.

     HMIDIOUT = (HANDLE | MIDIOUT),

.

     HMIDIIN  = (HANDLE | MIDIIN),

.

public enum MIXER_SETCONTROLDETAILSF : uint

.

     VALUE      = 0x00000000u,

.

Sample Code:

.

Please add some!

.

Alternative Managed API:

.

The ManagedWindowsApi project (http://mwinapi.sourceforge.net) provides a Mixer control.

.
Documentation
[mixerSetControlDetails] on MSDN
. .
Summary
Enumeration for the MMRESULT possible values in winmm.dll
.

public static enum MMRESULT : uint

.

  MMSYSERR_NOTENABLED     = 3,

.

  MMSYSERR_ALLOCATED      = 4,

.

  MMSYSERR_INVALHANDLE    = 5,

.

  MMSYSERR_INVALFLAG      = 10,

.

  MMSYSERR_INVALPARAM     = 11,

.

  MMSYSERR_HANDLEBUSY     = 12,

.

  MMSYSERR_INVALIDALIAS   = 13,

.

  MMSYSERR_DELETEERROR    = 18,

.

  MMSYSERR_VALNOTFOUND    = 19,

.

  WAVERR_STILLPLAYING     = 33,

.

Enum MMRESULT

.

  MMSYSERR_NOTENABLED = 3

.

  MMSYSERR_ALLOCATED = 4

.

  MMSYSERR_INVALHANDLE = 5

.

  MMSYSERR_INVALFLAG = 10

.

  MMSYSERR_INVALPARAM = 11

.

  MMSYSERR_HANDLEBUSY = 12

.

  MMSYSERR_INVALIDALIAS = 13

.

  MMSYSERR_DELETEERROR = 18

.

  MMSYSERR_VALNOTFOUND = 19

.

  WAVERR_STILLPLAYING = 33

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .
Summary
Plays a PCM sound file from a filename, resource name or registry alias
.

[DllImport("winmm.dll", SetLastError=true)]

.

static extern bool PlaySound(string pszSound, UIntPtr hmod, uint fdwSound);

.

[DllImport("winmm.dll", SetLastError=true)]

.

static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlags fdwSound);

.

<DllImport("winmm.dll")> _

.

Shared Function PlaySound( _

.

   ByVal szSound As String, _

.

   ByVal hModule As UIntPtr, _

.

   ByVal fdwSound As Integer) As Integer

.

Public Declare Auto Function PlaySound Lib "winmm.dll" (ByVal pszSound As String, ByVal hmod As IntPtr, ByVal fdwSound As Integer) As Boolean

.

Public Declare Auto Function PlaySound Lib "winmm.dll" (ByVal pszSound As Byte(), ByVal hmod As IntPtr, ByVal fdwSound As SoundFlags) As Boolean

.

You will need these flags for the fdwSound parameter

.

[Flags]

.

public enum SoundFlags

.

    /// <summary>play synchronously (default)</summary>

.

    /// <summary>play asynchronously</summary>

.

    /// <summary>silence (!default) if sound not found</summary>

.

    SND_NODEFAULT = 0x0002,

.

    /// <summary>pszSound points to a memory file</summary>

.

    /// <summary>loop the sound until next sndPlaySound</summary>

.

    SND_LOOP = 0x0008,    

.

    /// <summary>don't stop any currently playing sound</summary>

.

    /// <summary>Stop Playing Wave</summary>

.

    /// <summary>The pszSound parameter is an application-specific alias in the registry. You can combine this flag with the SND_ALIAS or SND_ALIAS_ID flag to specify an application-defined sound alias.</summary>

.

    SND_APPLICATION = 0x80,

.

    /// <summary>name is a registry alias</summary>

.

    SND_ALIAS = 0x00010000,

.

    /// <summary>alias is a predefined id</summary>

.

    SND_ALIAS_ID = 0x00110000,

.

    /// <summary>name is file name</summary>

.

    SND_FILENAME = 0x00020000,

.

<Flags()> _

.

    Public Enum SoundFlags As Integer

.

    ''' The sound is played synchronously, and PlaySound returns after

.

    ''' the sound event completes. This is the default behavior.

.

    ''' The sound is played asynchronously and PlaySound returns

.

    ''' immediately after beginning the sound. To terminate an

.

    ''' asynchronously played waveform sound, call PlaySound with

.

    ''' pszSound set to NULL.

.

    ''' No default sound event is used. If the sound cannot be found,

.

    ''' PlaySound returns silently without playing the default sound.

.

    SND_NODEFAULT = &H2

.

    ''' The pszSound parameter points to a sound loaded in memory.

.

    ''' The sound plays repeatedly until PlaySound is called again

.

    ''' with the pszSound parameter set to NULL. If this flag is

.

    ''' set, you must also set the SND_ASYNC flag.

.

    SND_LOOP = &H8

.

    ''' The specified sound event will yield to another sound event

.

    ''' that is already playing. If a sound cannot be played because

.

    ''' the resource needed to generate that sound is busy playing

.

    ''' another sound, the function immediately returns False without

.

    ''' playing the requested sound.

.

    ''' <remarks>If this flag is not specified, PlaySound attempts

.

    ''' to stop the currently playing sound so that the device can

.

    ''' be used to play the new sound.

.

    ''' Stop playing wave

.

    ''' The pszSound parameter is an application-specific alias in

.

    ''' the registry. You can combine this flag with the SND_ALIAS

.

    ''' or SND_ALIAS_ID flag to specify an application-defined sound

.

    ''' alias.

.

    SND_APPLICATION = &H80

.

    ''' If the driver is busy, return immediately without playing

.

    ''' The pszSound parameter is a system-event alias in the

.

    ''' registry or the WIN.INI file. Do not use with either

.

    ''' SND_FILENAME or SND_RESOURCE.

.

    SND_ALIAS = &H10000

.

    ''' The pszSound parameter is a file name. If the file cannot be

.

    ''' found, the function plays the default sound unless the

.

    ''' SND_NODEFAULT flag is set.

.

    SND_FILENAME = &H20000

.

To play a sound looping both SND_LOOP and SND_ASYNC flags have to be specified. Looped sounds only stop when PlaySound is called with pszSound set to NULL.

.

Sample Code:

.

public static void Play (string strFileName)

.

    PlaySound (strFileName, UIntPtr.Zero, (uint)(SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC));

.

public static void Play (byte[] waveData) //bad idea, see http://blogs.msdn.com/larryosterman/archive/2009/02/19/playsound-xxx-snd-memory-snd-async-is-almost-always-a-bad-idea.aspx

.

    PlaySound (waveData, IntPtr.Zero, PlayFlags.SND_ASYNC | PlayFlags.SND_MEMORY);

.

private void button2_Click(object sender, System.EventArgs e)

.

     bool result = PlaySound(@"C:\path\to\wav\file.wav" ,ip ,0);

.

Public Shared Sub Play(ByVal strFileName As String)

.

     PlaySound(strFileName, IntPtr.Zero, SoundFlags.SND_FILENAME Or SoundFlags.SND_ASYNC)

.

Public Shared Sub Play(ByVal waveData As Byte()) //bad idea, see http://blogs.msdn.com/larryosterman/archive/2009/02/19/playsound-xxx-snd-memory-snd-async-is-almost-always-a-bad-idea.aspx

.

     PlaySound(waveData, IntPtr.Zero, SoundFlags.SND_ASYNC Or SoundFlags.SND_MEMORY)

.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

.

     Dim result As Boolean = PlaySound("C:\path\to\wav\file.wav", IntPtr.Zero, ip)

.

Alternative Managed API:

.

In .Net 2.0 you can use the System.Media.SoundPlayer class instead:

.

SoundPlayer sound = new SoundPlayer(@"C:\Windows\Media\tada.wav");

.

sound.Load(); // can also be called asychronously i.e. LoadAsync()

.

sound.Play(); // default is to play asyncronously

.

My.Computer.Audio.Play("C:\path\to\wav\file.wav")

.

Or you can play a system specific sound:

.

My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)

.
Documentation
[PlaySound] on MSDN
.

http://msdn2.microsoft.com/en-us/library/ms712879.aspx

. .
Summary
The timeBeginPeriod function sets the minimum timer resolution for an application or device driver. Used to manipulate the timer frequency.
.

[DllImport("winmm.dll", EntryPoint="timeBeginPeriod")]

.

public static extern uint MM_BeginPeriod(uint uMilliseconds);

.

Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Integer) As Integer

.

Also see TimeGetTime (MM_GetTime) and TimeEndPeriod (MM_EndPeriod)

.

Please add some!

.

Sample Code:

.

  StreamWriter oWriter = null;

.

  MM_BeginPeriod(1); // set timer resolution to 1ms => freq=1000Hz

.

    // tickcount has resolution of 16.5ms, mmtime has 1ms

.

    for(int nLoop = 0; nLoop < 100000; nLoop++)

.

      oWriter.WriteLine("{0}: TickCount={1}, MMTime={2}", nLoop, Environment.TickCount, MM_GetTime());

.

    Console.WriteLine(oException.Message);

.

  finally

.

    if(oWriter != null)

.

      oWriter.Close();

.

Alternative Managed API:

.

Do you know one? Please contribute it!

. .
Summary
The timeEndPeriod function clears a previously set minimum timer resolution
.

[DllImport("winmm.dll", EntryPoint="timeEndPeriod")]

.

public static extern uint MM_EndPeriod(uint uMilliseconds);

.

Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Integer) As Integer

.

Also see timeBeginPeriod and timeEndPeriod

.

Please add some!

.

Sample Code:

.

See timeBeginPeriod for a sample

.

Alternative Managed API:

.

Do you know one? Please contribute it!

. .
Summary
The timeGetDevCaps function queries the timer device to determine its resolution.
.

[DllImport("winmm.dll", SetLastError=true)]

.

Declare Function timeGetDevCaps Lib "winmm.dll" (ByRef lpTimeCaps As TimeCaps, ByVal uSize As UInt32) As UInt32

.

http://www.pinvoke.net/default.aspx/Structures.TimeCaps

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Returns TIMERR_NOERROR if successful or TIMERR_STRUCT if it fails to return the timer device capabilities.

.

TIMERR_NOERROR is defined as UInt32 0 value.

.

Please add some!

.

Sample Code:

.

Please add some!

. .

[DllImport("winmm.dll", SetLastError=true)]

.

Declare Function timeGetSystemTime Lib "winmm.dll" (TODO) As TODO

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .
Summary
The timeGetTime function retrieves the system time, in milliseconds. The system time is the time elapsed since Windows was started.
.

[DllImport("winmm.dll", EntryPoint="timeGetTime")]

.

public static extern uint MM_GetTime();

.

<DllImport("winmm.dll", EntryPoint := "timeGetTime")> _

.

Public Shared Function MM_GetTime() As UInteger

.

Unlike Environment.TickCount, you can directly set the resolution of this timer with the TimeBeginPeriod function.

.

Please add some!

.

Sample Code:

.

See TimeBeginPeriod for a sample

.

Alternative Managed API:

.

Do you know one? Please contribute it!

. .

[DllImport("winmm.dll", SetLastError=true)]

.

static extern UInt32 timeKillEvent( UInt32 timerEventId );

.

Declare Function timeKillEvent Lib "winmm.dll" (TODO) As TODO

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

.
Documentation
[timeKillEvent] on MSDN
. .

[DllImport("winmm.dll", SetLastError=true)]

.

static extern UInt32 timeSetEvent( UInt32 msDelay, UInt32 msResolution,

.

            TimerEventHandler handler, ref UInt32 userCtx, UInt32 eventType );

.

Declare Function timeSetEvent Lib "winmm.dll" (TODO) As TODO

.

TimerEventHandler

.

Alternative Managed API:

.

Please add some!

.

Sample Code:

.

    public class MMTimer : IDisposable

.

    //Lib API declarations

.

    [DllImport("Winmm.dll", CharSet = CharSet.Auto)]

.

    static extern uint timeSetEvent(uint uDelay, uint uResolution, TimerCallback lpTimeProc, UIntPtr dwUser, uint fuEvent);

.

    [DllImport("Winmm.dll", CharSet = CharSet.Auto)]

.

    static extern uint timeKillEvent(uint uTimerID);

.

    [DllImport("Winmm.dll", CharSet = CharSet.Auto)]

.

    [DllImport("Winmm.dll", CharSet = CharSet.Auto)]

.

    [DllImport("Winmm.dll", CharSet = CharSet.Auto)]

.

    [Flags]

.

    public enum fuEvent : uint

.

        TIME_ONESHOT = 0,      //Event occurs once, after uDelay milliseconds.

.

        TIME_CALLBACK_FUNCTION = 0x0000,  /* callback is function */

.

        //TIME_CALLBACK_EVENT_SET = 0x0010, /* callback is event - use SetEvent */

.

        //TIME_CALLBACK_EVENT_PULSE = 0x0020  /* callback is event - use PulseEvent */

.

    //Delegate definition for the API callback

.

    delegate void TimerCallback(uint uTimerID, uint uMsg, UIntPtr dwUser, UIntPtr dw1, UIntPtr dw2);

.

    //IDisposable code

.

    private bool disposed = false;

.

    public void Dispose()

.

        GC.SuppressFinalize(this);

.

    private void Dispose(bool disposing)

.

        Dispose(false);

.

    /// The callback used by the the API

.

    TimerCallback thisCB;

.

    /// The timer elapsed event

.

    public event EventHandler Timer;

.

    protected virtual void OnTimer(EventArgs e)

.

        if (Timer != null)

.

    public MMTimer()

.

        //Initialize the API callback

.

    public void Stop()

.

        lock (this)

.

            timeKillEvent(id);

.

            Debug.WriteLine("MMTimer " + id.ToString() + " stopped");

.

    /// <param name="ms">Timer interval in milliseconds</param>

.

    public void Start(uint ms, bool repeat)

.

        //Kill any existing timer

.

        //Set the timer type flags

.

        fuEvent f = fuEvent.TIME_CALLBACK_FUNCTION | (repeat ? fuEvent.TIME_PERIODIC : fuEvent.TIME_ONESHOT);

.

        lock (this)

.

        Debug.WriteLine("MMTimer " + id.ToString() + " started");

.

        //Callback from the MMTimer API that fires the Timer event. Note we are in a different thread here

. .

[DllImport ("winmm.dll", EntryPoint="waveInAddBuffer", SetLastError=true)]

.

public static extern uint waveInAddBuffer(IntPtr hwi, ref WAVEHDR pwh, uint cbwh);

.

<DllImport("winmm.dll")> _

.

Shared Function waveInAddBuffer(<MarshalAs(UnmanagedType.I4)> ByVal hwi As Integer, ByVal pwh As IntPtr, ByVal cbwh As UInteger) As MMRESULT

.

<DllImport("winmm.dll")> _

.

Shared Function waveInAddBuffer(<MarshalAs(UnmanagedType.I4)> ByVal hwi As Integer, ByRef pwh As WAVEHDR, ByVal cbwh As UInteger) As MMRESULT

.

MMRESULT

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

When recording waveform audio, usually buffers are allocated with unmanaged functions and kept in an IntPtr() array; for this reason the function is provided in two versions, one processing a WAVEHDR ByRef and the other working with an IntPtr.

.

Instead of allocating memory using an unmanaged function, it is possible to lock the WAVEHDR and Buffer in place using GCHandle.Allocate(object, GCHandleType.Pinned);

.

Sample Code:

.

Please add some!

. .
Summary
The waveInClose function closes the given waveform-audio input device.
.

[DllImport("winmm.dll", SetLastError=true)]

.

static extern uint waveInClose(IntPtr hwi);

.

<DllImport("winmm.dll")> _

.

Shared Function waveInClose(<MarshalAs(UnmanagedType.I4)> ByVal hwi As Integer) As MMRESULT

.

MMRESULT

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

.
Documentation
[waveInClose] on MSDN
. .

[DllImport("winmm.dll",SetLastError=true)]

.

public static extern uint waveInGetNumDevs();

.

<DllImport("winmm.dll")> _

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .
Summary
.

[Flags]

.

    enum WaveInOpenFlags : uint

.

        CALLBACK_NULL = 0,

.

        CALLBACK_FUNCTION = 0x30000,

.

        CALLBACK_EVENT = 0x50000,

.

        CALLBACK_WINDOW = 0x10000,

.

        CALLBACK_THREAD = 0x20000,

.

<Flags()> _

.

Friend Enum WaveInOpenFlags As UInteger

.

  CALLBACK_NULL = 0

.

  CALLBACK_FUNCTION = &H30000

.

  CALLBACK_EVENT = &H50000

.

  CALLBACK_WINDOW = &H10000

.

  CALLBACK_THREAD = &H20000

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .
Summary
.

[DllImport("winmm.dll", SetLastError=true)]

.

static extern TODO WaveInOpenFlags(TODO);

.

<Flags()> _

.

Friend Enum WaveInOpenFlags As UInteger

.

  CALLBACK_NULL = 0

.

  CALLBACK_FUNCTION = &H30000

.

  CALLBACK_EVENT = &H50000

.

  CALLBACK_WINDOW = &H10000

.

  CALLBACK_THREAD = &H20000

.

Alternative Managed API:

.

Do you know one? Please contribute it!

.

Please add some!

.

Sample Code:

.

Please add some!

. .

PLEASE DELETE THIS PAGE, IT HAS BEEN MADE IN MISTAKE WHEN I MISTYPED THE URL NAME.

Cut off search results after 60. Please refine your search.


 
Access PInvoke.net directly from VS: