Help converting WinAPI struct

M

MuZZy

HI,

I would really appreciate some hwlp with this:
Here is the WinAPI struct used in call to winapi function wavInGetDevCaps:

typedef struct
{
WORD wMid;
WORD wPid;
MMVERSION vDriverVersion;
TCHAR szPname[MAXPNAMELEN];
DWORD dwFormats;
WORD wChannels;
WORD wReserved1;
} WAVEINCAPS


I need to convert it into c# struct:

[StructLayout(LayoutKind.Sequential)] public struct WAVEINCAPS
{
Int16 wMid;
Int16 wPid;
int vDriverVersion;
public char[] szPname;
int dwFormats;
Int16 wChannels;
Int16 wReserved;
}


Well, first i'm not sure i need to use this attribute,
second, i don't know how to set size of szPname in declaration (seems
like it's not the way c# operates with arrays)


Any ideas on thaat?

Thank you in advance,
Andrey
 
M

Mattias Sjögren

Well, first i'm not sure i need to use this attribute,

The StructLayout attribute? You should probably keep it here, and add

CharSet=CharSet.Auto

to it.

second, i don't know how to set size of szPname in declaration (seems
like it's not the way c# operates with arrays)

[MarshalAs(UnmanagedType.ByValArray, SizeConst=MAXPNAMELEN)]
public char[] szPname;

or

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAXPNAMELEN)]
public string szPname;



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top