Hi,
I have been trying to marshal data from C# onto a C function which accepts a pointer to a structure.
The structure is as below...
=====================
struct Details
{
int ssno;
char name[50];
char hobbies[10][30];
ADDRESS addr[3];
}DETAILS;
struct Address
{
int hno;
char street[20];
}ADDRESS;
int updateDetails(DETAILS *);
=======================
But I am having problem with sending double dimensional arrays e.g: the hobbies field.
I am not aware to find a proper match to Marshal it.
Even I have given LPArray, ByValArray etc., but it doesn't work.
I am looking for a equivalent structure that I can define in C# code.
The structures that I have created in C# and that do not work
===================
[StructLayout(LayoutKind.Sequential,CharSet=CharSet .Ansi)]
public struct DETAILS
{
public int ssno;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst = 50)]
public String name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=10)]
public String[] hobbies;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public ADDRESS[] addr;
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet .Ansi)]
public struct ADDRESS
{
public int hno;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst = 20)]
public String street;
}
======================
I tried creating my own C dll and created a function to read and print the data.
The data comes fine until ssno and name.
But all other hobbies and Address details are junk characters.
Any inputs would be of great help.