public static void GenerateMusicProperty(ref MusicProperty prop, WAVEFORMATEX format, EDataType type, byte[] data) { IntPtr propPtr = Marshal.AllocHGlobal(Marshal.SizeOf(prop)); Marshal.StructureToPtr(prop, propPtr, false); IntPtr formatPtr = Marshal.AllocHGlobal(Marshal.SizeOf(format)); Marshal.StructureToPtr(format, formatPtr, false); IntPtr ptr = Marshal.AllocHGlobal(data.Length); Marshal.Copy(data, 0, ptr, data.Length); WaveFileManagerNative.generateMusicProperty(propPtr, formatPtr, type, ptr, (uint)data.Length); prop = Marshal.PtrToStructure <MusicProperty>(propPtr); Marshal.FreeHGlobal(propPtr); Marshal.FreeHGlobal(formatPtr); // It should be free, but can't do that. // This bug will be fixed. // Marshal.FreeHGlobal(ptr); }
public static void CreateFile(string path, MusicProperty prop) { IntPtr propPointer = Marshal.AllocHGlobal(Marshal.SizeOf(prop)); Marshal.StructureToPtr(prop, propPointer, false); WaveFileManagerNative.createFile(path, propPointer); Marshal.FreeHGlobal(propPointer); }