Quote:
Originally Posted by Cyprus106
Thanks a whole lot, Mark! I'm not in that much of a hurry anyways.
I gotta say, you are always on the ball, and prompt. Thanks a lot for that!
No worries mate, glad to help!
This is a class called VoiceRecorder.cs ... It's fairly simple to use. It's a slightly modified version of one I found on thecodeproject a while back (I'm VERY sorry, I can't find the original URL) it launches the inbuilt audio recording facilities of Windows Mobile.
You invoke it by using
-
VoiceRecorder vr = new VoiceRecorder("myFileName.wav");
-
vr.show();
-
And it behaves just like a dialogbox.
It took me AGES to try and get something like this working, so it's always nice when we can skip out all that hassle and help eachother.
-
using System;
-
using System.Data;
-
using System.Runtime.InteropServices;
-
-
#region Attempt 1
-
namespace MyNameSpace
-
{
-
public class VoiceRecorder
-
{
-
#region API prototypes
-
[DllImport("voicectl.dll", EntryPoint = "VoiceRecorder_Create")]
-
private unsafe static extern IntPtr VoiceRecorder_Create(CM_VOICE_RECORDER* voicerec);
-
-
[DllImport("coredll.dll", EntryPoint = "GetForegroundWindow")]
-
private unsafe static extern IntPtr GetForegroundWindow();
-
#endregion
-
-
[StructLayout(LayoutKind.Sequential)]
-
public unsafe struct CM_VOICE_RECORDER
-
{
-
public int cb;
-
public wndStyle dwStyle;
-
public int xPos;
-
public int yPos;
-
public IntPtr hwndParent;
-
public int id;
-
public char* lpszRecordFileName;
-
}
-
-
public enum wndStyle : uint
-
{
-
VRS_NO_OKCANCEL = 0x0001, // No OK/CANCLE displayed
-
VRS_NO_NOTIFY = 0x0002, // No parent Notifcation
-
VRS_MODAL = 0x0004, // Control is Modal
-
VRS_NO_OK = 0x0008, // No OK displayed
-
VRS_NO_RECORD = 0x0010, // No RECORD button displayed
-
VRS_PLAY_MODE = 0x0020, // Immediately play supplied file when launched
-
VRS_NO_MOVE = 0x0040, // Grip is removed and cannot be moved around by the user
-
VRS_RECORD_MODE = 0x0080, // Immediately record when launched
-
VRS_STOP_DISMISS = 0x0100 // Dismiss control when stopped
-
}
-
-
private unsafe CM_VOICE_RECORDER _VoiceRec;
-
private IntPtr _hRecorder;
-
private string wavFile = @"\My Documents\VRec_0.wav";
-
-
private IntPtr _Hwnd = (IntPtr)0;
-
-
public IntPtr Hwnd
-
{
-
get { return _Hwnd; }
-
set
-
{
-
_VoiceRec.hwndParent = value;
-
_Hwnd = value;
-
}
-
}
-
-
public unsafe VoiceRecorder(string _audioFile)
-
{
-
wavFile = _audioFile;
-
_hRecorder = new IntPtr();
-
char[] temp = new char[200];
-
-
this.Hwnd = GetForegroundWindow();
-
-
// Populate temp with the file path of the WAV file
-
Buffer.BlockCopy(wavFile.ToCharArray(), 0, temp, 0, 2 * wavFile.Length);
-
-
fixed (char* lpszFileName = temp)
-
{
-
_VoiceRec = new CM_VOICE_RECORDER();
-
-
_VoiceRec.hwndParent = _Hwnd;
-
_VoiceRec.dwStyle = wndStyle.VRS_NO_MOVE | wndStyle.VRS_MODAL;
-
_VoiceRec.cb = (int)Marshal.SizeOf(_VoiceRec);
-
_VoiceRec.xPos = -1;
-
_VoiceRec.yPos = -1;
-
_VoiceRec.lpszRecordFileName = lpszFileName;
-
}
-
}
-
-
// Show the voice recorder
-
public unsafe void Show()
-
{
-
fixed (CM_VOICE_RECORDER* _VoiceRecPtr = &_VoiceRec)
-
{
-
_hRecorder = VoiceRecorder_Create(_VoiceRecPtr);
-
}
-
}
-
}
-
}
-
#endregion
-