Hi, I am trying to marshal this structure to be used by my application in C#, Right now is being consumed succesfully by the c++ dll, however I think the partition of the structure is wrong, for the Name parameter returns always funky values.
this is the c++ structure:
#define MAX_PATH 260
typedef struct {
BYTE nAlternate;
char Name[MAX_PATH];
DWORD NbSectors;
PMAPPINGSECTOR pSectors;
} MAPPING, *PMAPPING;
this is how I converted it I think that as long as it is sequential it doesn't have gaps in the memory between objects (correct me if wrong).
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MAPPING
{
public byte nAlternate;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=260)]
public string Name;
public UInt32 NbSectors;
public MAPPINGSECTOR pSectors;
}
after running the value for Name is really weird(like chinese characters yes i tried changing the char set with no success) I'd say incomplete
here is the structure for MAPPINGSECTOR
typedef struct {
DWORD dwStartAddress;
DWORD dwAliasedAddress;
DWORD dwSectorIndex;
DWORD dwSectorSize;
BYTE bSectorType;
BOOL UseForOperation;
} MAPPINGSECTOR, *PMAPPINGSECTOR;
this is how is converted it.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct MAPPINGSECTOR
{
public UInt32 dwStartAddress;
public UInt32 dwAliasedAddress;
public UInt32 dwSectorIndex;
public UInt32 dwSectorSize;
public byte bSectorType;
public bool UseForOperation;
}
I also tried to assign the memory explicitly by using field offset but it would return me error saying that there was overlapping if somebody could show me how to assign the memory explicitly I think that could solve my problem.
Thanks in Advance.