How do I send a buffer down to a driver and receive back a new buffer from
that driver?
I received the new buffer from the driver but it give me the wrong data.
And how do I know if DeviceIoControl send my data down?
Is there a way to convert the IntPtr buffer to byte[] buffer?
thanks in advance,
//My structure
[StructLayout(LayoutKind.Sequential)]
public struct STATUS_PACKET
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]
public byte[] dest_mac;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]
public byte[] sour_mac; //6bytes
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public byte[] e_type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=1)]
public byte[] status_packet;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=9)]
public byte[] zero;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
public byte[] micro_rev;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
public byte[] fpga_rev;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=22)]
public byte[] swith_name;
}
//.................
public bool StatusPacketCheck(byte [] sourceAdd)
{
bool bStatus = true;
int retBytes = 0;
IntPtr hDevice;
IntPtr pAlloc = IntPtr.Zero;
int [] statusDest = new int[1024];
STATUS_PACKET myStatus = new STATUS_PACKET();
myStatus.source_mac = sourceAdd;
byte SizeOfBuff = (byte)(System.Runtime.InteropServices.Marshal.Size Of(
myStatus ));
//Allocates a block of memory
IntPtr StatusBuffPtr = Marshal.AllocHGlobal(SizeOfBuff);
hDevice = GetDriverDeviceHandle();
if ((int)hDevice != INVALID_HANDLE_VALUE)
{
bStatus = DeviceIoControl(hDevice, // device to be queried
FSConstants.CF_VERSION, // operation to perform
StatusBuffPtr,
SizeOfBuff,
StatusBuffPtr,
SizeOfBuff,
ref retBytes, // # bytes returned
IntPtr.Zero);
if(!bStatus)
{
CloseHandle(hDevice);
hDevice = IntPtr.Zero;
return bStatus;
}
else
{
myStatus = (STATUS_PACKET)Marshal.PtrToStructure( StatusBuffPtr,
typeof(STATUS_PACKET));
Marshal.FreeHGlobal(StatusBuffPtr);
}
}
else
{
return bStatus = false;
}
CloseHandle(hDevice);
hDevice = IntPtr.Zero;
return bStatus;
}
}