P/Invoke problem

  • Thread starter Thread starter Dirk Reske
  • Start date Start date
D

Dirk Reske

Hello,

I have following sourcecode:

[DllImport("msacm32.dll", CharSet=CharSet.Unicode)]
private static extern int acmStreamOpen(ref int phas,int
had,MPEGLAYER3WAVEFORMAT pwfxSrc,WAVEFORMATEX pwfxDest,WAVEFILTER pwFltr,int
callBack,int dwInstance,int dwOpen);

WAVEFORMATEX waveFormat = new WAVEFORMATEX();
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nChannels = 2;
waveFormat.nSamplesPerSec = 44100;
waveFormat.wBitsPerSample = 16;
waveFormat.nBlockAlign = 4;
waveFormat.nAvgBytesPerSec = 4*44100;
waveFormat.cbSize = 0;

MPEGLAYER3WAVEFORMAT mp3Format = new MPEGLAYER3WAVEFORMAT();
mp3Format.wfx = new WAVEFORMATEX();
mp3Format.wfx.cbSize = MPEGLAYER3_WFX_EXTRA_BYTES;
mp3Format.wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
mp3Format.wfx.nChannels = 2;
mp3Format.wfx.nAvgBytesPerSec = 128 * (1024/8);
mp3Format.wfx.wBitsPerSample = 0;
mp3Format.wfx.nBlockAlign = 1;
mp3Format.wfx.nSamplesPerSec = 44100;
mp3Format.fdwFlags = MPEGLAYER3_FLAG_PADDING_OFF;
mp3Format.nBlockSize = MP3_BLOCK_SIZE;
mp3Format.nFramesPerBlock = 1;
mp3Format.nCodecDelay = 1393;
mp3Format.wID = 1;

int acmStream = 0;

WAVEFILTER filter = new WAVEFILTER();

//--------------------------------------------------------------------------
-
int result = acmStreamOpen(ref acmStream, 0,mp3Format,waveFormat,
filter,0,0,0);
//HERE IS MY PROBLEM...THIS FUNCTION ALLWAYS RETURNS 11 (INVALID PARAM)
//--------------------------------------------------------------------------
-

Perhaps someone finds out, where my mistake is....
 
It would be helpfull if you also supplied the WAVEFORMATEX and MPEGLAYER3WAVEFORMAT structures.

Willy.
 
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
public struct WAVEFORMATEX
{
public short wFormatTag;
public short nChannels;
public int nSamplesPerSec;
public int nAvgBytesPerSec;
public short nBlockAlign;
public short wBitsPerSample;
public short cbSize;
}

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
public struct MPEGLAYER3WAVEFORMAT
{
public WAVEFORMATEX wfx;
public short wID;
public int fdwFlags;
public short nBlockSize;
public short nFramesPerBlock;
public short nCodecDelay;
}

Willy Denoyette said:
It would be helpfull if you also supplied the WAVEFORMATEX and
MPEGLAYER3WAVEFORMAT structures.
Willy.

Hello,

I have following sourcecode:

[DllImport("msacm32.dll", CharSet=CharSet.Unicode)]
private static extern int acmStreamOpen(ref int phas,int
had,MPEGLAYER3WAVEFORMAT pwfxSrc,WAVEFORMATEX pwfxDest,WAVEFILTER pwFltr,int
callBack,int dwInstance,int dwOpen);

WAVEFORMATEX waveFormat = new WAVEFORMATEX();
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nChannels = 2;
waveFormat.nSamplesPerSec = 44100;
waveFormat.wBitsPerSample = 16;
waveFormat.nBlockAlign = 4;
waveFormat.nAvgBytesPerSec = 4*44100;
waveFormat.cbSize = 0;

MPEGLAYER3WAVEFORMAT mp3Format = new MPEGLAYER3WAVEFORMAT();
mp3Format.wfx = new WAVEFORMATEX();
mp3Format.wfx.cbSize = MPEGLAYER3_WFX_EXTRA_BYTES;
mp3Format.wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
mp3Format.wfx.nChannels = 2;
mp3Format.wfx.nAvgBytesPerSec = 128 * (1024/8);
mp3Format.wfx.wBitsPerSample = 0;
mp3Format.wfx.nBlockAlign = 1;
mp3Format.wfx.nSamplesPerSec = 44100;
mp3Format.fdwFlags = MPEGLAYER3_FLAG_PADDING_OFF;
mp3Format.nBlockSize = MP3_BLOCK_SIZE;
mp3Format.nFramesPerBlock = 1;
mp3Format.nCodecDelay = 1393;
mp3Format.wID = 1;

int acmStream = 0;

WAVEFILTER filter = new WAVEFILTER();

//--------------------------------------------------------------------------
-
int result = acmStreamOpen(ref acmStream, 0,mp3Format,waveFormat,
filter,0,0,0);
//HERE IS MY PROBLEM...THIS FUNCTION ALLWAYS RETURNS 11 (INVALID PARAM)
//--------------------------------------------------------------------------
-

Perhaps someone finds out, where my mistake is....
 
Dirk,
[DllImport("msacm32.dll", CharSet=CharSet.Unicode)]
private static extern int acmStreamOpen(ref int phas,int
had,MPEGLAYER3WAVEFORMAT pwfxSrc,WAVEFORMATEX pwfxDest,WAVEFILTER pwFltr,int
callBack,int dwInstance,int dwOpen);

All the struct parameters should be passed by ref.

private static extern int acmStreamOpen(ref int phas,int had,ref
MPEGLAYER3WAVEFORMAT pwfxSrc,ref WAVEFORMATEX pwfxDest,ref WAVEFILTER
pwFltr,int callBack,int dwInstance,int dwOpen);

And personally I'd use IntPtr rahter than int for all handles, but as
long as you only run on Win32 int should work as well.



Mattias
 
I also get Error:11

Mattias Sjögren said:
Dirk,
[DllImport("msacm32.dll", CharSet=CharSet.Unicode)]
private static extern int acmStreamOpen(ref int phas,int
had,MPEGLAYER3WAVEFORMAT pwfxSrc,WAVEFORMATEX pwfxDest,WAVEFILTER pwFltr,int
callBack,int dwInstance,int dwOpen);

All the struct parameters should be passed by ref.

private static extern int acmStreamOpen(ref int phas,int had,ref
MPEGLAYER3WAVEFORMAT pwfxSrc,ref WAVEFORMATEX pwfxDest,ref WAVEFILTER
pwFltr,int callBack,int dwInstance,int dwOpen);

And personally I'd use IntPtr rahter than int for all handles, but as
long as you only run on Win32 int should work as well.



Mattias
 
Back
Top