Function WaveInOpen doesn't return meesage MM_WIM_OPEN?

J

jrumanek

Hallo,

I have problem with function WaveInOpen . This function doesn't return
meesage MM_WIM_OPEN?

Shall YOU help me pleas?

Any suggestions?

Thank you!

My code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;


namespace SoundApplication
{
public partial class frmMain : Form
{
public int wav;
public IntPtr hWaveIn = IntPtr.Zero;
public IntPtr hWaveOut = IntPtr.Zero;
public IntPtr dwCallback = IntPtr.Zero;

public frmMain()
{
InitializeComponent();

}

public class Winmm
{
public struct WAVEFORMAT
{
public short wFormatTag;
public short nChannels;
public uint nSamplesPerSec;
public uint nAvgBytesPerSec;
public short nBlockAlign;
public short wBitsPerSample;
public short cbSize;
}

public class WAVEHDR
{
public IntPtr lpData = IntPtr.Zero;
public uint dwBufferLength = 0;
public uint dwBytesRecorded = 0;
public uint dwUser = 0;
public uint dwFlags = 0;
public uint dwLoops = 0;
public IntPtr lpNext = IntPtr.Zero;
public uint reserved = 0;
}

private const string mmdll = "winmm.dll";

// WaveIn calls
[DllImport(mmdll)]
public static extern int waveInGetNumDevs();
[DllImport(mmdll)]
public static extern int waveInOpen(ref IntPtr lphWaveIn,
uint DEVICEID, ref WAVEFORMAT lpWaveFormat,
IntPtr dwCallback, uint dwInstance, uint dwFlags);

//WaveOut calls
[DllImport(mmdll)]
public static extern int waveOutOpen(ref IntPtr
lphWaveOut, uint DEVICEID, ref WAVEFORMAT lpWaveFormat,
IntPtr dwCallback, uint dwInstance, uint dwFlags);
}

private void btOpen_Click(object sender, EventArgs e)
{
const uint WAVE_MAPPER = unchecked((uint)(-1));
const int CALLBACK_WINDOW = 0x00010000;
const int CALLBACK_TASK = 0x00020000;
const int CALLBACK_FUNCTION = 0x00030000;
const int CALLBACK_EVENT = 0x00050000;

Winmm.WAVEFORMAT wavFmt;
wavFmt.wFormatTag = 1;
wavFmt.nChannels = 1;
wavFmt.nSamplesPerSec = 44100;
wavFmt.nAvgBytesPerSec = 44100;
wavFmt.nBlockAlign = 1;
wavFmt.wBitsPerSample = 8;
wavFmt.cbSize = 0;

wav = Winmm.waveInOpen(ref hWaveIn, WAVE_MAPPER, ref
wavFmt, dwCallback, 0, CALLBACK_WINDOW);
MessageBox.Show(wav.ToString());
wav = Winmm.waveOutOpen(ref hWaveOut, WAVE_MAPPER, ref
wavFmt, dwCallback, 0, CALLBACK_WINDOW);
}

protected override void WndProc(ref Message m)
{

const int MM_WIM_OPEN = 0x3BE;
const int MM_WIM_CLOSE = 0x3BF;
const int MM_WIM_DATA = 0x3C0;

const int MM_WOM_OPEN = 0x3BB;
const int MM_WOM_CLOSE = 0x3BC;
const int MM_WOM_DONE = 0x3BD;
if (m.Msg == MM_WIM_OPEN || m.Msg == MM_WOM_OPEN || m.Msg
== MM_WIM_CLOSE)
{
MessageBox.Show("TEST");
}
switch (m.Msg)
{
case MM_WIM_OPEN:
MessageBox.Show("MM_WIM_OPEN");
break;
case MM_WIM_CLOSE:
MessageBox.Show("MM_WOM_OPEN");
break;
case MM_WOM_OPEN:
MessageBox.Show("MM_WOM_OPEN");
break;


}
base.WndProc(ref m);
}

}
}
 
M

Mattias Sjögren

I have problem with function WaveInOpen . This function doesn't return
meesage MM_WIM_OPEN?

You must pass in the window handle of the window that should process
the message as the dwCallback parameter. As far as I can see, it's
always IntPtr.Zero in your code.


Mattias
 
J

jrumanek

You must pass in the window handle of the window that should process
the message as the dwCallback parameter. As far as I can see, it's
always IntPtr.Zero in your code.

Mattias

Thank You!
But I don't know how can I pass in the window handle of the window?
Shall You write me code for pass handle?
I was using Builder C++ and I'm beginner in C#.
Jarek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top