Problems with MIDIHDR

I am trying to write a wrapper library for MIDI functions in WinMM.dll, but I am having problems with long MIDI messages. I found this in PIvnoke.net (I added the first line):

[StructLayout(LayoutKind.Sequential)] public struct MIDIHDR { IntPtr lpData; int dwBufferLength; int dwBytesRecorded; IntPtr dwUser; int dwFlags; MIDIHDR lpNext; IntPtr reserved; int dwOffset; IntPtr dwReserved; } 

But when compiling, I get an error:

Error 1 Struct element 'WinMMM.MidiWrapper.MIDIHDR.lpNext' of type 'WinMMM.MidiWrapper.MIDIHDR' causes a loop in the structure structure C: \ Users \ Alex \ Documents \ Visual Studio 2010 \ Projects \ WinMMM \ WinMMM \ MidiWrapper.cs 219 219 Winmmm

I am using Visual Studio Ultimate 2010, I am creating a C # class library and any help would be appreciated!

+4
source share
3 answers

You can change:

 MIDIHDR lpNext; 

in

 IntPtr lpNext; 

to solve your immediate problem.

The MIDL compiler cannot dereference the chain of these structures, but if the API call takes one as an argument, with this change, the link to the next will be decoded as a raw pointer, like the first lpData field.

+4
source

I am not sure that the final bit of the correct one is correct. dwReserved is an array of four DWORD_PTR (see MIDIHDR on MSDN ). You can use something like this:

  // http://msdn.microsoft.com/en-us/library/dd798449%28VS.85%29.aspx [StructLayout(LayoutKind.Sequential)] public struct MIDIHDR { public string lpData; public int dwBufferLength; public int dwBytesRecorded; public IntPtr dwUser; public int dwFlags; public IntPtr lpNext; public IntPtr reserved; public int dwOffset; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public IntPtr[] dwReserved; } 
+1
source

You can also change the MIDIHDR declaration from a structure to a class type.

0
source

All Articles