C structs in C#

G

Guest

I want to access a dll and one of the arguments is the following C struct:

typedef struct {
int Size;
char chVersion[32]; /* version number. */
} cdVersionInfo;

The chVersion parameter is returned by the dll function. How would I
represent this struct in C#? I tried the following but it doesn't compile.
[StructLayout(LayoutKind.Sequential)]
public struct cdVersionInfo
{
 
M

Mattias Sjögren

Bob,
The chVersion parameter is returned by the dll function. How would I
represent this struct in C#?

Make it

public struct cdVersionInfo
{
public int Size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)]
public char[] chVersion;
}



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