C# Struct No Parameterless Constructor? See what I need to accomplish

Posted by Changeling on Stack Overflow See other posts from Stack Overflow or by Changeling
Published on 2010-03-03T14:32:06Z Indexed on 2010/06/05 11:12 UTC
Read the original article Hit count: 181

Filed under:
|
|
|
|

I am using a struct to pass to an unmanaged DLL as so -

[StructLayout(LayoutKind.Sequential)]
        public struct valTable
        {
            public byte type;
            public byte map;
            public byte spare1;
            public byte spare2;
            public int par;
            public int min;
            public byte[] name;
            public valTable()
            {
                name = new byte[24];
            }
        }

The code above will not compile because VS 2005 will complain that "Structs cannot contain explicit parameterless constructors". In order to pass this struct to my DLL, I have to pass an array of struct's like so valTable[] val = new valTable[281];

What I would like to do is when I say new, the constructor is called and it creates an array of bytes like I am trying to demonstrate because the DLL is looking for that byte array of size 24 in each dimension.

How can I accomplish this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about dll