problem importing native struct...

My environment:

Windows 7 x64 Professional
Visual Studio 2010

Here is the problem...

In file mmsystem.h (MIDI system definitions, NOT a file I created, but part of the Visual Studio environment) there exists the following definition:

/* MIDI data block header */
typedef struct midihdr_tag {
LPSTR lpData; /* pointer to locked data block */
DWORD dwBufferLength; /* length of data in data block */
DWORD dwBytesRecorded; /* used for input only */
DWORD_PTR dwUser; /* for client's use */
DWORD dwFlags; /* assorted flags (see defines) */
struct midihdr_tag far *lpNext; /* reserved for driver */
DWORD_PTR reserved; /* reserved for driver */
#if (WINVER >= 0x0400)
DWORD dwOffset; /* Callback offset into buffer */
DWORD_PTR dwReserved[8]; /* Reserved for MMSYSTEM */

I have to reference and use this definition in my managed code.

In a previous version of the application I'm developing (compiled using /clr:oldSyntax) the following worked. It compiled and ran successfully:

#include <MMSystem.h>
namespace AudioConfigManager
public __gc class MidiDevice : public System::Object
private: struct midihdr_tag __nogc midiHeaderIn[NUM_MIDI_HEADERS];

Now I'm forced to recompile the same application using the /clr switch. This is as far as I've gotten:

#include <MMSystem.h>
namespace AudioConfigManager
public ref class MidiDevice : public System::Object
private: struct midihdr_tag __nogc midiHeaderIn[NUM_MIDI_HEADERS];

This of course generates a compiler error:

"clr\MidiDevice.h(15): error C4368: cannot define 'midiHeaderIn' as a member of managed 'AudioConfigManager::MidiDevice': mixed types are not supported"

Of course it does. The problem is, after searching for HOURS on the web, I have not found a way to make this work. This post would be far too long if I detailed all the syntax I've tried, so I'll keep it short and just ask the question - how do I make this work?

REMEMBER - I have to import the original definition of MIDIHDR as it appears in the system include file "mmsystem.h". I can't modify that file to make the structure ref/value/interface.

I know this can be done. Can someone help me please? Many thanks in advance.



Two possabilities:

1. Move the original declaration unchanged to an unmanaged code section surrounded by #pragma:

#pragma managed(push,off)
struct midihdr_tag *midiHeaderIn[NUM_MIDI_HEADERS];
#pragma managed(pop)

2. The syntax I was seeking:

private: array<struct midihdr_tag*> ^midiHeaderIn;

Solution #2 requires specific allocation, best accomplished in the constructor:

midiHeaderIn = gcnew array<struct midihdr_tag*>(NUM_MIDI_HEADERS);
Last edited on
Topic archived. No new replies allowed.