Groups | Blog | Home
all groups > c# > september 2003 >

c# : Dllimport for mpglib.dll


purplenachos NO[at]SPAM yahoo.com
9/7/2003 10:13:41 PM
Hi,

I am trying to write a C# wrapper class for the famous mp3 decoder
mpg123. I have gotten the win32 .dll version of it, and have a sample
C program that uses the .dll which I think is pretty good. I have not
found a C# or even a C/C++ wrapper class of mpglib.dll so this might
be a difficult task since mpglib.dll only decodes the .mp3 files to
PCM format.

The first thing I need to do is use DllImport to import the library
functions. Does anyone know how to import the following C functions?
The fixed size character array in a struct is what confuses me.


struct mpstr { char c[40000]; };

typedef BOOL (*INITMP3) (struct mpstr *mp);
typedef void (*EXITMP3) (struct mpstr *mp);
typedef int (*DECODEMP3) (struct mpstr *mp, char *inmemory, int
inmemsize,
char *outmemory, int outmemsize, int
*done);

Dennis Doomen
9/8/2003 11:18:37 AM
public struct MPStr
{
[MarshalAs(UnmanagedType.ByValArray, ArraySubType=typeof(char),
SizeConst=40000)]
char[] c;
}

If those function definitions you mention are actually function
pointers, you must define them as delegates in C#. E.g.

public delegate bool InitMp3Delegate(MPStr mp);
public delegate bool ExitMp3Delegate(MPStr mp);
public delegate bool DecodeMp3Delegate(MPStr mp, char[] inmemory, int
inmemsize, char[] outmemoery, int outmemsize, out int done)


[quoted text, click to view]


--
Dennis Doomen
Sioux T.S.O. Netherlands

dennis.doomen@sioux.nl
AddThis Social Bookmark Button