473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DeviceIoControl Help,

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;
}
}

Nov 17 '05 #1
0 1026

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ewoo | last post by:
I'm trying to write a wrapper in csharp to wrap DeviceIoControl() win32 method for IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS control code--without much luck. I've seen lots of examples out there for...
2
by: Michael Allen | last post by:
I would like to perform something similar to the below function in C# .NET. The C++ below code is from a Microsoft DDK sample driver application. Specifically, I would like to perform Device I/O...
3
by: Mads Tjørnelund Toustrup | last post by:
I'm having difficulties converting the GET_CONFIGURATION_HEADER from the IOCTL_CDROM_GET_CONDIGURATION DeviceIoControl command to usable C# code. The C struct look like this: typedef struct...
1
by: Pixie | last post by:
I am trying to query the change journal using the deviceIOControl API. The API doesn't return an error, but all of the values in the output buffer are zero, and they shouldn't be. My code is below. I...
0
by: Pixie | last post by:
We are successfully getting a handle to a drive using createfile then using that handle to query the change journal using DeviceIOControl with the paramter FSCTL_QUERY_USN_DATA. However when we try...
1
by: Juan Pedro Gonzalez | last post by:
Helo, I'm having problems here with the input buffer.... Ive defined the API call as: <System.Runtime.InteropServices.DllImport("kernel32", SetLastError:=True)> _ Private Shared Function...
5
by: Lou | last post by:
is there a VB .NET way to use the API "DeviceIoControl"? -Lou
0
by: Andrew | last post by:
Hello I am trying to port some code and I am running into some issues I may or may not be able to solve on my own and would appreciate your help Basically I am trying to open the Tun Driver...
4
by: =?Utf-8?B?TWFyaW5h?= | last post by:
Does any know any sample of how to do a basic DeviceIoControl with something like IOCTL_BATTERY_GETSYSTEMPOWERSTATUSEX2 in C# I have been stuck all week :( and google doesnt yield anything of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.