470,647 Members | 1,313 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

mmioDescendParent: invalid parameter

Hi all,

can anybody tell me what he invalid parameter is in this code. When I
try to execute the mmioDescendParent I get a returncode 11, meaning
that an invalid parameter has been passed. I just don't know which one
and therefor not how to improve my code.

Regards,

Rubycon

P.S.: you can find the original VB6 code at
http://custom.programming-in.net/art...?f=mmioDescend
converted to VB.Net this code also gives me a returncode 11, so no help
there.

-------------------------------------------------------------------------------

using System;
using System.Runtime.InteropServices;

namespace WilfredClassLibrary1
{
/// <summary>
/// Summary description for WindowsMultiMediaInterface.
/// </summary>
public class WindowsMultiMediaInterface
{
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct MMIOINFO
{
public long dwFlags;
public long fccIOProc;
public long pIOProc;
public long wErrorRet;
public long htask;
public long cchBuffer;
public string pchBuffer;
public string pchNext;
public string pchEndRead;
public string pchEndWrite;
public long lBufOffset;
public long lDiskOffset;
public long adwInfo1;
public long adwInfo2;
public long adwInfo3;
public long adwInfo4;
public long dwReserved1;
public long dwReserved2;
public long hmmio;
public void Initialize()
{
}
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=4)]
public struct MMIOFLAGS
{
// private const int MMIO_ALLOCBUF = 65536;
public const long MMIO_ALLOCBUF = 65536;
public const long MMIO_COMPAT = 0;
public const long MMIO_CREATE = 4096;
public const long MMIO_CREATELIST = 64;
public const long MMIO_CREATERIFF = 32;
public const long MMIO_DEFAULTBUFFER = 8192;
public const long MMIO_DELETE = 512;
public const long MMIO_DENYNONE = 64;
public const long MMIO_DENYREAD = 48;
public const long MMIO_DENYWRITE = 32;
public const long MMIO_DIRTY = 268435456;
public const long MMIO_EMPTYBUF = 16;
public const long MMIO_EXCLUSIVE = 16;
public const long MMIO_EXIST = 16384;
public const long MMIO_FHOPEN = 16;
public const long MMIO_FINDCHUNK = 16;
public const long MMIO_FINDLIST = 64;
public const long MMIO_FINDPROC = 262144;
public const long MMIO_FINDRIFF = 0x0020;
// public const long MMIO_FINDRIFF = 32;
public const long MMIO_GETTEMP = 131072;
public const long MMIO_INSTALLPROC = 65536;
public const long MMIO_OPEN_VALID = 262143;
public const long MMIO_PARSE = 256;
public const long MMIO_PUBLICPROC = 268435456;
public const long MMIO_READ = 0;
public const long MMIO_READWRITE = 2;
public const long MMIO_REMOVEPROC = 131072;
public const long MMIO_RWMODE = 3;
public const long MMIO_SHAREMODE = 112;
public const long MMIO_TOUPPER = 16;
public const long MMIO_UNICODEPROC = 16777216;
public const long MMIO_VALIDPROC = 285671424;
public const long MMIO_WRITE = 1;
public const long SEEK_CUR = 1;
public const long SEEK_END = 2;
public const long SEEK_SET = 3;
public const long TIME_BYTES = 4;
public const long WHDR_DONE = 1;
IntPtr hmmio;
public void Initialize()
{
}
}
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
public struct MMCKINFO
{
public long ckid;
public long ckSize;
public long fccType;
public long dwDataOffset;
public long dwFlags;
}
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
public struct WAVEHDR
{
public long lpData;
public long dwBufferLength;
public long dwBytesRecorded;
public long dwUser;
public long dwFlags;
public long dwLoops;
public long lpNext;
public long Reserved;
}
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
public struct WAVEINCAPS
{
public int wMid;
public int wPid;
public long vDriverVersion;
public string szPname;
public long dwFormats;
public int wChannels;
}
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
public struct WAVEFORMAT
{
public int wFormatTag;
public int nChannels;
public long nSamplesPerSec;
public long nAvgBytesPerSec;
public int nBlockAlign;
public int wBitsPerSample;
public int cbSize;
}
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
public struct MMTIME
{
public long wType;
public long u;
public long x;
}
// Definition of fields used here and there
const int NUM_BUFFERS = 5;
const double BUFFER_SECONDS = 0.1;
long rc; // Return Code
long hmmioIn; // File Handle
long dataOffset; // Start of audio data in wave file
long audioLength; // number of bytes in audio data
long pFormat; // pointer to wave format
string formatBuffer; // buffer to hold the wave format
long startPos; // sample where we started playback from
WAVEFORMAT format; // wave format structure
long i; // loop control variable
long j; // loop control variable
long[] hmem; // memory handles
long[] pmem; // memory pointers
WAVEHDR[] hdr; // wave headers
long bufferSize; // size of output buffers
bool fPlaying; // is file currently playing
bool fFileOpen; // is file currently open
long hWaveOut; // waveout handle
string msg; // message buffer

private const long WAVERR_BASE = 32;
private const long MMSYSERR_BASE = 0;

public enum MMSYSERR : long
{
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)
}

private enum WAVERR : long
{
NONE = 0,
BADFORMAT = WAVERR_BASE + 0,
STILLPLAYING = WAVERR_BASE + 1,
UNPREPARED = WAVERR_BASE + 2,
SYNC = WAVERR_BASE + 3,
LASTERROR = WAVERR_BASE + 3
}
/// <comment>
/// More info on http://custom.programming-in.net/
/// </comment>
/// <remarks>
/// winmm.dll: mmio functions
/// </remarks>
[DllImport("winmm.dll")] public static extern long mmioAdvance(long
hmmio, ref MMIOINFO lpmmioinfo, long uFlags);
[DllImport("winmm.dll")] public static extern long mmioAscend(long
hmmio, ref MMCKINFO lpck, long uFlags);
[DllImport("winmm.dll")] public static extern long mmioClose(long
hmmio, long uFlags);
[DllImport("winmm.dll")] public static extern long
mmioCreateChunk(long hmmio, ref MMCKINFO lpck, long uFlags);
[DllImport("winmm.dll")] public static extern long mmioDescend(long
hmmio, ref MMCKINFO lpck, ref MMCKINFO lpckParent, long uFlags);
[DllImport("winmm.dll", EntryPoint="mmioDescend")] static extern long
mmioDescendParent(long hmmio, MMCKINFO lpck, long x, long uFlags);
[DllImport("winmm.dll")] public static extern long mmioFlush(long
hmmio, long uFlags);
[DllImport("winmm.dll")] public static extern long mmioGetInfo(long
hmmio, ref MMIOINFO lpmmioinfo, long uFlags);
[DllImport("winmm.dll")] public static extern long
mmioInstallIOProcA(string fccIOProc_4, long pIOProc, long dwFlags);
// [DllImport("winmm.dll", EntryPoint="mmioOpen")] public static
extern long mmioOpenA(string szFileName, ref MMIOINFO lpmmioinfo, long
dwOpenFlags);
[DllImport("winmm.dll", EntryPoint="mmioOpenA")] private static
extern long mmioOpen(string szFileName, ref MMIOINFO lpmmioinfo, long
dwOpenFlags);
[DllImport("winmm.dll")] public static extern long mmioRead(long
hmmio, string pch, long cch);
[DllImport("winmm.dll", EntryPoint="mmioRead")] static extern long
mmioReadString(long hmmio, string pch, long cch);
[DllImport("winmm.dll", EntryPoint="mmioRename")] public static
extern long mmioRenameA(string szFileName, string SzNewFileName, ref
MMIOINFO lpmmioinfo, long dwRenameFlags);
[DllImport("winmm.dll")] public static extern long mmioSeek(long
hmmio, long lOffset, long iOrigin);
[DllImport("winmm.dll")] public static extern long
mmioSendMessage(long hmmio, long uMsg, long lParam1, long lParam2);
[DllImport("winmm.dll")] public static extern long mmioSetBuffer(long
hmmio, string pchBuffer, long cchBuffer, long uFlags);
[DllImport("winmm.dll")] public static extern long mmioSetInfo(long
hmmio, ref MMIOINFO lpmmioinfo, long uFlags);
// [DllImport("winmm.dll", EntryPoint="mmioStringToFOURCC")] public
static extern long mmioStringToFOURCCA(string sz, long uFlags);
[DllImport("winmm.dll", EntryPoint="mmioStringToFOURCCA")] public
static extern long mmioStringToFOURCC(string sz, long uFlags);
[DllImport("winmm.dll")] public static extern long mmioWrite(long
hmmio, string pch, long cch);
/// <remarks>
/// winmm.dll: wave functions
/// </remarks>
[DllImport("winmm.dll")] static extern long waveOutGetPosition(long
hWaveOut, MMTIME lpInfo, long uSize);
[DllImport("winmm.dll")] static extern long waveOutOpen(long
hWaveOut, long uDeviceID, string format, long dwCallback, ref bool
fPlaying, long dwFlags);
[DllImport("winmm.dll")] static extern long waveOutPrepareHeader(long
hWaveIn, WAVEHDR lpWaveInHdr, long uSize);
[DllImport("winmm.dll")] static extern long waveOutReset(long
hWaveIn);
[DllImport("winmm.dll")] static extern long
waveOutUnprepareHeader(long hWaveIn, WAVEHDR lpWaveInHdr, long uSize);
[DllImport("winmm.dll")] static extern long waveOutClose(long
hWaveIn);
[DllImport("winmm.dll", EntryPoint="waveInGetDevCapsA")] static
extern long waveOutGetDevCaps(long uDeviceID, WAVEINCAPS lpCaps, long
uSize);
[DllImport("winmm.dll")] static extern long waveOutGetNumDevs();
[DllImport("winmm.dll", EntryPoint="waveInGetErrorTextA")] static
extern long waveOutGetErrorText(long err, string lpText, long uSize);
[DllImport("winmm.dll")] static extern long waveOutWrite(long
hWaveOut, WAVEHDR lpWaveOutHdr, long uSize);
/// <remarks>
/// kernel32.dll
/// </remarks>
[DllImport("kernel32")] static extern long GlobalAlloc(long wFlags,
long dwBytes);
[DllImport("kernel32")] static extern long GlobalLock(long hmem);
[DllImport("kernel32")] static extern long GlobalFree(long hmem);
// "Any" is onbekend, vervangen door object.
// [DllImport("kernel32", EntryPoint="RtlMoveMemory")] static extern
void CopyStructFromPtr(Any struct, int ptr, int cb);
// [DllImport("kernel32", EntryPoint="RtlMoveMemory")] static extern
void CopyPtrFromStruct(int ptr, Any struct, int cb);
// [DllImport("kernel32", EntryPoint="RtlMoveMemory")] static extern
void CopyStructFromString(Any dest, string source, int cb);
[DllImport("kernel32", EntryPoint="RtlMoveMemory")] static extern
void CopyStructFromPtr(object cpy, long ptr, long cb);
[DllImport("kernel32", EntryPoint="RtlMoveMemory")] static extern
void CopyPtrFromStruct(long ptr, object cpy, long cb);
[DllImport("kernel32", EntryPoint="RtlMoveMemory")] static extern
void CopyStructFromString(object cpy, string source, long cb);
/// <remarks>
/// user32.dll
/// </remarks>
[DllImport("user32", EntryPoint="PostMessageA")] static extern long
PostWavMessage(long hwnd, long wMsg, long wParam, ref WAVEHDR hdr);

public WindowsMultiMediaInterface()
{
//
// TODO: Add constructor logic here
//
}
public void CloseFile()
{
mmioClose(hmmioIn, 0);
fFileOpen = false;
}
public long OpenFile(string soundfile)
{
MMCKINFO mmckinfo = new MMCKINFO();
MMCKINFO mmckinfoParentIn = new MMCKINFO();
MMCKINFO mmckinfoSubchunckIn = new MMCKINFO();
MMIOINFO mmioinf = new MMIOINFO();
// Close previously opened file (if any)
CloseFile();
if(soundfile == "")
{
return -1;
}
// Open the inputfile
hmmioIn = mmioOpen(soundfile, ref mmioinf, MMIOFLAGS.MMIO_READ);
// hmmioIn = mmioOpenA(soundfile, ref mmioinf, MMIOFLAGS.MMIO_READ);
if(hmmioIn == 0)
{
return mmioinf.wErrorRet;
}
// check if this is a wave file
// mmckinfoParentIn.fccType = mmioStringToFOURCCA("WAVE", 0);
mmckinfoParentIn.fccType = mmioStringToFOURCC("WAVE", 0);
rc = mmioDescendParent(hmmioIn, mmckinfoParentIn, 0,
MMIOFLAGS.MMIO_FINDRIFF);
// rc = mmioDescendParent(hmmioIn, mmckinfoParentIn,
Convert.ToInt64(null), MMIOFLAGS.MMIO_FINDRIFF);
if(Convert.ToInt16(rc) != Convert.ToInt16(MMSYSERR.NOERROR))
{
CloseFile();
return rc;
}
// Get format info
// mmckinfoSubchunckIn.ckid = mmioStringToFOURCCA("fmt", 0);
mmckinfoSubchunckIn.ckid = mmioStringToFOURCC("fmt", 0);
rc = mmioDescend(hmmioIn, ref mmckinfoSubchunckIn, ref
mmckinfoParentIn, MMIOFLAGS.MMIO_FINDCHUNK);
if(Convert.ToInt16(rc) != Convert.ToInt16(MMSYSERR.NOERROR))
{
CloseFile();
return rc;
}
rc = mmioReadString(hmmioIn, formatBuffer,
mmckinfoSubchunckIn.ckSize);
if(rc == -1)
{
CloseFile();
return rc;
}
rc = mmioAscend(hmmioIn, ref mmckinfoSubchunckIn, 0);
CopyStructFromString(format, formatBuffer, format.cbSize);
// find the data subchunck
// mmckinfoSubchunckIn.ckid = mmioStringToFOURCCA("data", 0);
mmckinfoSubchunckIn.ckid = mmioStringToFOURCC("data", 0);
rc = mmioDescend(hmmioIn, ref mmckinfoSubchunckIn, ref
mmckinfoParentIn, MMIOFLAGS.MMIO_FINDCHUNK);
if(Convert.ToInt16(rc) != Convert.ToInt16(MMSYSERR.NOERROR))
{
CloseFile();
return rc;
}
dataOffset = mmioSeek(hmmioIn, 0, MMIOFLAGS.SEEK_CUR);

// get the lenght of the audio
audioLength = mmckinfoSubchunckIn.ckSize;

// allocate audio bufffers
bufferSize = format.nSamplesPerSec * format.nBlockAlign *
format.nChannels * Convert.ToInt64(BUFFER_SECONDS);
bufferSize = bufferSize - (bufferSize % format.nBlockAlign);
for(int i = 1; i <= NUM_BUFFERS; i++)
{
GlobalFree(hmem[i]);
hmem[i] = GlobalAlloc(0, bufferSize);
pmem[i] = GlobalLock(hmem[i]);
}
fFileOpen = true;
return 0; // uiteindelijk altijd iets teruggeven
}
public MMSYSERR OpenFile(string fileName, short Flags)
{
return OpenFile(fileName, Flags, MMIOFLAGS.MMIO_DEFAULTBUFFER);
}

public MMSYSERR OpenFile(string fileName, short Flags, long
bufferSize)
{
if (!(System.IO.File.Exists(fileName)))
{
throw new System.IO.FileNotFoundException();
}
MMIOINFO tmpMMIOInfo = new MMIOINFO();
tmpMMIOInfo.Initialize();
if (System.Convert.ToBoolean(Flags & MMIOFLAGS.MMIO_ALLOCBUF))
{
tmpMMIOInfo.cchBuffer = bufferSize;
}
object mvarhndMMIO = null;
mvarhndMMIO = mmioOpen(fileName, ref tmpMMIOInfo, Flags);
// mvarhndMMIO = mmioOpenA(fileName, ref tmpMMIOInfo, Flags);
return ((MMSYSERR)(tmpMMIOInfo.wErrorRet));
}
}
}
Nov 17 '05 #1
2 5058
>can anybody tell me what he invalid parameter is in this code. When I
try to execute the mmioDescendParent I get a returncode 11, meaning
that an invalid parameter has been passed. I just don't know which one
and therefor not how to improve my code.


Well most of your declarations are incorrect. Most if not all
occurances of long should be replaced with int. Try finding correct
declarations at http://www.pinvoke.net

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2
Mattias,

I replaced all long occurances with int. This has now led me to
receiving a returncode of 10, meaning "invalid flag". I now need to
find the correct specification and/or value for MMIOFLAG FINDRIFF.
Unfortunately pinvoke.net offers no help. I you know something on this
subject, please let me know.

Thanks in advance,

Rubycon

Mattias Sjögren <ma********************@mvps.org> wrote in message news:<#t**************@TK2MSFTNGP14.phx.gbl>...
can anybody tell me what he invalid parameter is in this code. When I
try to execute the mmioDescendParent I get a returncode 11, meaning
that an invalid parameter has been passed. I just don't know which one
and therefor not how to improve my code.


Well most of your declarations are incorrect. Most if not all
occurances of long should be replaced with int. Try finding correct
declarations at http://www.pinvoke.net

Mattias

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by David Veeneman | last post: by
1 post views Thread by Andy G | last post: by
1 post views Thread by Hifni Shahzard | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.