Hi I am trying to convert the C/C++ Strcut to C# and how to fill the structure member with address of another structure in C#?
C/C++ Struct looks like:
typedef struct _NDISUIO_QUERY_OID
{
NDIS_OID Oid;
PTCHAR ptcDeviceName;
UCHAR Data[sizeof(ULONG)];
} NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID;
typedef struct My_Struct
{
//leT's have 2 variables...
UINT a;
UINT b;
//sTRUCT may have many no.of variables depending upon the requirement
}My_STATS, *PMy_STATS;
PNDISUIO_QUERY_OID pQueryOid = NULL;
pQueryOid = (PNDISUIO_QUERY_OID)malloc(sizeof(NDISUIO_QUERY_OID)+ sizeof(My_STATS)) ;
PMy_STATS Statistics;
pQueryOid->Oid = ulOIDCode;//Required OID
pQueryOid->ptcDeviceName = AUB_NAME;//REquired STRING
memcpy(pQueryOid->Data, Statistics, sizeof(My_STATS));
IoctlResult = DeviceIoControl(
handle,
IOCTL_NDISUIO_QUERY_OID_VALUE,
pQueryOid,
sizeof(NDISUIO_QUERY_OID)+ sizeof(My_STATS),
pQueryOid,
sizeof(NDISUIO_QUERY_OID)+ sizeof(My_STATS),
&dwReturnedBytes,
NULL);
Getting IoctlResult Success in C++;
My C# Struct is:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct _NDISUIO_QUERY_OID
{
public uint Oid;
[MarshalAs(UnmanagedType.LPWStr)]
public string ptcDeviceName;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = sizeof(uint))]
public byte[] Data;
};
My_STATS Sta_Conn_Info = new My_STATS();
_NDISUIO_QUERY_OID QueryOid = new _NDISUIO_QUERY_OID();
QueryOid.Oid = ulOIDCode; // required OID
QueryOid.ptcDeviceName = STRING;//Required String
//Imported coredll.dll with required prototype for this.
IoctlResult = DeviceIoControl(
handle,
IOCTL_NDISUIO_QUERY_OID_VALUE,
ref QueryOid,
sizeof(NDISUIO_QUERY_OID)+ sizeof(My_STATS),
ref QueryOid,
sizeof(NDISUIO_QUERY_OID)+ sizeof(My_STATS),
ref dwReturnedBytes,
NULL
);
Problem: How to marshal the NDISUIO_QUERY Struct to copy the another structure to its Data Member in C#?? and how to replace the memcpy as in c++?
Any suggestions or guidelines will be helpful.. :)
Thanks :)