G
Guest
Hi,
I trying to get something that seems to be simple to work: I’m using VS
2005/C#. I want to get the information of my WaveOut devices. The WAVEOUTCAPS
structure is defined in C++ as:
typedef struct {
WORD wMid;
WORD wPid;
MMVERSION vDriverVersion;
TCHAR szPname[MAXPNAMELEN];
DWORD dwFormats;
WORD wChannels;
WORD wReserved1;
DWORD dwSupport;
} WAVEOUTCAPS;
In C# I declare it as:
public struct WAVEOUTCAPS
{
public ushort wMid;
public ushort wPid;
public ulong vDriverVersion;
public char[] szPname;
public ulong dwFormats;
public ushort wChannels;
public ushort wReserved1;
public ulong dwSupport;
}
And later in the code:
WAVEOUTCAPS waveinfo = new WAVEOUTCAPS();
waveinfo.szPname = new char[32];
the waveOutGetDevCaps function is declared as
[DllImport("winmm.dll")]
public static extern int waveOutGetDevCaps(int uDeviceID, ref WAVEOUTCAPS
lpCaps, int uSize);
everything up to here compiles and runs fine. As soon as I call
waveOutGetDevCaps(0, ref waveinfo, Marshal.SizeOf(waveinfo));
my program crashes with the error:
System.Runtime.InteropServices.SafeArrayTypeMismatchException was unhandled
Message="Specified array was not of the expected type."
Any ideas what I’m doing wrong?
I trying to get something that seems to be simple to work: I’m using VS
2005/C#. I want to get the information of my WaveOut devices. The WAVEOUTCAPS
structure is defined in C++ as:
typedef struct {
WORD wMid;
WORD wPid;
MMVERSION vDriverVersion;
TCHAR szPname[MAXPNAMELEN];
DWORD dwFormats;
WORD wChannels;
WORD wReserved1;
DWORD dwSupport;
} WAVEOUTCAPS;
In C# I declare it as:
public struct WAVEOUTCAPS
{
public ushort wMid;
public ushort wPid;
public ulong vDriverVersion;
public char[] szPname;
public ulong dwFormats;
public ushort wChannels;
public ushort wReserved1;
public ulong dwSupport;
}
And later in the code:
WAVEOUTCAPS waveinfo = new WAVEOUTCAPS();
waveinfo.szPname = new char[32];
the waveOutGetDevCaps function is declared as
[DllImport("winmm.dll")]
public static extern int waveOutGetDevCaps(int uDeviceID, ref WAVEOUTCAPS
lpCaps, int uSize);
everything up to here compiles and runs fine. As soon as I call
waveOutGetDevCaps(0, ref waveinfo, Marshal.SizeOf(waveinfo));
my program crashes with the error:
System.Runtime.InteropServices.SafeArrayTypeMismatchException was unhandled
Message="Specified array was not of the expected type."
Any ideas what I’m doing wrong?