S
Suja
Hi All,
I have a WIN32 DLL which pass some information to a .NET based
application via the windows messages. When I try to convert this data
in the managed code, I am getting junk data. Does any have any clue on
whats wrong?. Here is the code snippet.
//From WIN32 DLL, I am passing the TOTAL_STATUS structure as wParam of
the message
#define MAX_DATA_SIZE = 100;
#define MAX_NO_STATUS = 10;
typedef struct _STATUS
{
BYTE Status1[MAX_NO_STATUS];
BYTE Status2[MAX_NO_STATUS];
}STATUS , *STATUS;
typedef struct _TOTAL_STATUS
{
STATUS Sts ;
BYTE RawSts[MAX_DATA_SIZE];
}TOTAL_STATUS, *PTOTAL_STATUS;
//In the managed code, I am defining the structure as follows
const int MAX_DATA_SIZE = 100;
const int MAX_NO_STATUS = 10;
[ StructLayout( LayoutKind.Sequential, Pack = 1 ) ]
struct _STATUS
{
[MarshalAs(UnmanagedType.ByValArray,ArraySubType = UnmanagedType.U1,
SizeConst=MAX_NO_STATUS)]
public byte[] Status1;
public byte[] Status2;
}
[ StructLayout( LayoutKind.Sequential, Pack = 1 ) ]
struct TOTAL_STATUS
{
public _STATUS Sts ;
[MarshalAs(UnmanagedType.ByValArray,ArraySubType = UnmanagedType.U1,
SizeConst=MAX_DATA_SIZE)]
public byte[] RawSts;
}
//Doing a conversion as follows
TOTAL_STATUS TotalSts = (TOTAL_STATUS)Marshal.PtrToStructure(m.WParam,
typeof(TOTAL_STATUS));
But the values in "TotalSts " are junk values( I did zero outting in
both locations and after conversion I am getting random values)
Any idea about whats wrong here?
Thanks in advance
Suja.
I have a WIN32 DLL which pass some information to a .NET based
application via the windows messages. When I try to convert this data
in the managed code, I am getting junk data. Does any have any clue on
whats wrong?. Here is the code snippet.
//From WIN32 DLL, I am passing the TOTAL_STATUS structure as wParam of
the message
#define MAX_DATA_SIZE = 100;
#define MAX_NO_STATUS = 10;
typedef struct _STATUS
{
BYTE Status1[MAX_NO_STATUS];
BYTE Status2[MAX_NO_STATUS];
}STATUS , *STATUS;
typedef struct _TOTAL_STATUS
{
STATUS Sts ;
BYTE RawSts[MAX_DATA_SIZE];
}TOTAL_STATUS, *PTOTAL_STATUS;
//In the managed code, I am defining the structure as follows
const int MAX_DATA_SIZE = 100;
const int MAX_NO_STATUS = 10;
[ StructLayout( LayoutKind.Sequential, Pack = 1 ) ]
struct _STATUS
{
[MarshalAs(UnmanagedType.ByValArray,ArraySubType = UnmanagedType.U1,
SizeConst=MAX_NO_STATUS)]
public byte[] Status1;
public byte[] Status2;
}
[ StructLayout( LayoutKind.Sequential, Pack = 1 ) ]
struct TOTAL_STATUS
{
public _STATUS Sts ;
[MarshalAs(UnmanagedType.ByValArray,ArraySubType = UnmanagedType.U1,
SizeConst=MAX_DATA_SIZE)]
public byte[] RawSts;
}
//Doing a conversion as follows
TOTAL_STATUS TotalSts = (TOTAL_STATUS)Marshal.PtrToStructure(m.WParam,
typeof(TOTAL_STATUS));
But the values in "TotalSts " are junk values( I did zero outting in
both locations and after conversion I am getting random values)
Any idea about whats wrong here?
Thanks in advance
Suja.