Shurikn Posted June 8, 2005 Posted June 8, 2005 I never used marshaling before, but I did some c++ code and I wanted it's equivalence in c#. My code used a struct like this: 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: [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; } (it's 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.... 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 i'm just missing a namespace or using call,m anybody can help? and while you're looking at my code, does it actually look right? Quote
Administrators PlausiblyDamp Posted June 8, 2005 Administrators Posted June 8, 2005 Try adding a using System.Runtime.InteropServices; to the top of the file. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Shurikn Posted June 8, 2005 Author Posted June 8, 2005 Thank! it's what was missing. now i just have to make that code work... ^^ Quote
Recommended Posts