Arrays in structs

  • Thread starter Thread starter cody
  • Start date Start date
C

cody

IIRC you can simply use datatype string for that. Additionally you could use
the MarshalAs attribute but Iam not sure.
 
I need to set up an array in a struct for passing to a win32 api call . How
do I do this please?
("Name" is actually a zero terminated ascii string, so a pointer to a
better way to do this would also be appreciated)

eg
[StructLayout(LayoutKind.Sequential)]

public struct Details

{

public int UniqueID;

public byte[] Name[43]; << wrong here, also should be ascii chars

public eState Status;

}
 
cody said:
IIRC you can simply use datatype string for that. Additionally you could
use
the MarshalAs attribute but Iam not sure.

thanks for answering so quickly cody but that was all gobbledegook at my
level (I just about understood the IIRC bit)
Can you give me a code snippet or link to example please
 
public struct Details
{
public int UniqueID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=43)]
public string Name;
public eState Status;
}



Mattias
 
see matthias's reply.

Claire said:
thanks for answering so quickly cody but that was all gobbledegook at my
level (I just about understood the IIRC bit)
Can you give me a code snippet or link to example please
 
Back
Top