I never used marshaling before, but I did some c++ code and I wanted its equivalence in c#. My code used a struct like this:
but in c# we cant fix the array in a declaration on struct. So i searched on these forum and fond how to use marshaling and did this:
(its not the same thing because my c++ code was to acess a wave ane the c# code is acessing an AVI file)
I find this Marshaling thing very confused but I think im using it right. the problem is, my compilator does not like it at all....
Maybe im just missing a namespace or using call,m anybody can help?
and while youre looking at my code, does it actually look right?
PHP:
struct EnteteWave
{
char chunkID [4];
int chunkSize;
char format [4];
char subchunk1ID [4];
int subchunk1Size;
short audioFormat;
short numChannels;
int sampleRate;
int byteRate;
short blockAlign;
short bitsPerSample;
char subchunk2ID [4];
int subchunk2Size;
};
but in c# we cant fix the array in a declaration on struct. So i searched on these forum and fond how to use marshaling and did this:
PHP:
[StructLayout(LayoutKind.Sequential)]
public struct EnteteAvi
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
public byte[] chunkId;
public Int32 fileSize;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
public byte[] fileType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
public byte[] subChunk1ID;
public Int32 subChunk1Size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
public byte[] subChunk1Type;
public Int32 cb;
public Int32 MicroSecPerFrame;
public Int32 MaxBytePerSec;
public Int32 PaddingGranularity;
public Int32 Flags;
public Int32 TotalFrames;
public Int32 InitialFrames;
public Int32 Streams;
public Int32 SuggestedBufferSize;
public Int32 Width;
public Int32 Height;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
public Int32[] Reserved;
}
(its not the same thing because my c++ code was to acess a wave ane the c# code is acessing an AVI file)
I find this Marshaling thing very confused but I think im using it right. the problem is, my compilator does not like it at all....
Code:
C:\Documents and Settings\Nicolas Dufour\Mes documents\Visual Studio Projects\ZoneMedia\AVI.cs(30): The type or namespace name StructLayout could not be found (are you missing a using directive or an assembly reference?)
Maybe im just missing a namespace or using call,m anybody can help?
and while youre looking at my code, does it actually look right?