waveOutOpen (coredll)
Last changed: -172.212.31.206

.
Summary
TODO - a short description

C# Signature:

[DllImport ("coredll.dll", EntryPoint="waveOutOpen", SetLastError=true)]
public static extern int waveOutOpen(out IntPtr t, int id, WaveFormatEx pwfx, IntPtr dwCallback, int dwInstance, int fdwOpen);

VB Signature:

(TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Taken from openNetCF in OpenNETCF.Win32.Wave

Tips & Tricks:

Please add some!

Sample Code:

using System;

using System.Data;

using System.Runtime.InteropServices;

namespace waveoutopen

{

    class Tester
    {
        static void Main(string[] args)
        {
            Tester t = new Tester();
            t.Run();
        }

        public void Run()
        {
            WAVEFORMATEX testFormat = new WAVEFORMATEX();    
            testFormat.wFormatTag = 1;
            testFormat.wBitsPerSample = 16;   // 8,16
            testFormat.nChannels = 2;
            testFormat.nSamplesPerSec = 44100;
            testFormat.nBlockAlign = (ushort)(testFormat.nChannels *
                (testFormat.wBitsPerSample / 8));
            testFormat.nAvgBytesPerSec = (testFormat.nSamplesPerSec *
                testFormat.nBlockAlign);
            testFormat.cbSize = 0;

            IntPtr m_hwi = IntPtr.Zero;
            IntPtr hwnd = IntPtr.Zero;

            MMSYSERR result = waveOutOpen(ref m_hwi, WAVE_MAPPER,
                ref testFormat, 0, 0, 0);

            Console.WriteLine("and the result of open is {0}",result.ToString());

            Console.WriteLine("End Of Run - Enter to Quit");
            Console.ReadLine();
        }

        private const int MMSYSERR_BASE = 0;
        public const uint WAVE_MAPPER = unchecked((uint)(-1));

        public enum MMSYSERR : int
        {
            NOERROR = 0,
            ERROR = (MMSYSERR_BASE + 1),
            BADDEVICEID = (MMSYSERR_BASE + 2),
            NOTENABLED = (MMSYSERR_BASE + 3),
            ALLOCATED = (MMSYSERR_BASE + 4),
            INVALHANDLE = (MMSYSERR_BASE + 5),
            NODRIVER = (MMSYSERR_BASE + 6),
            NOMEM = (MMSYSERR_BASE + 7),
            NOTSUPPORTED = (MMSYSERR_BASE + 8),
            BADERRNUM = (MMSYSERR_BASE + 9),
            INVALFLAG = (MMSYSERR_BASE + 10),
            INVALPARAM = (MMSYSERR_BASE + 11),
            HANDLEBUSY = (MMSYSERR_BASE + 12),
            INVALIDALIAS = (MMSYSERR_BASE + 13),
            BADDB = (MMSYSERR_BASE + 14),
            KEYNOTFOUND = (MMSYSERR_BASE + 15),
            READERROR = (MMSYSERR_BASE + 16),
            WRITEERROR = (MMSYSERR_BASE + 17),
            DELETEERROR = (MMSYSERR_BASE + 18),
            VALNOTFOUND = (MMSYSERR_BASE + 19),
            NODRIVERCB = (MMSYSERR_BASE + 20),
            LASTERROR = (MMSYSERR_BASE + 20),
            BADFORMAT = (MMSYSERR_BASE + 32)
        }

        [DllImport ("coredll.dll")]
        private static extern MMSYSERR waveOutOpen(
            ref IntPtr phwo,
            uint uDeviceID,
            ref WAVEFORMATEX pwfx,
            uint dwCallback,
            uint dwInstance,
            uint fdwOpen
            );

        [StructLayout(LayoutKind.Sequential)]
        public unsafe struct WAVEFORMATEX
        {      
            public ushort wFormatTag;
            public ushort nChannels;
            public uint nSamplesPerSec;
            public uint nAvgBytesPerSec;
            public ushort nBlockAlign;
            public ushort wBitsPerSample;
            public ushort cbSize;          
        }
    }

}

Documentation
waveOutOpen on MSDN