473,320 Members | 1,987 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,320 software developers and data experts.

DeviceIoControl conversion...

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 _GET_CONFIGURATION_HEADER {
UCHAR DataLength[4];
UCHAR Reserved[2];
UCHAR CurrentProfile[2];
UCHAR Data[0];
} GET_CONFIGURATION_HEADER, *PGET_CONFIGURATION_HEADER;

Taken from this site:
http://msdn.microsoft.com/library/de...6a488c.xml.asp

I hope there is a helpful soul out there who can help me out?
Nov 17 '05 #1
8 1423
Try this:

struct GET_CONFIGURATION_HEADER
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
public byte[] DataLength;
private ushort Reserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public byte[] CurrentProfile;
}
Mattias

Nov 17 '05 #2


"Mattias Sjögren" wrote:
Try this:

struct GET_CONFIGURATION_HEADER
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=4)]
public byte[] DataLength;
private ushort Reserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public byte[] CurrentProfile;
}
Mattias


Yes, this looks good, but there are more to it. The CurrentProfile is
actually an enumerator value of type FEATURE_PROFILE_TYPE:

typedef enum _FEATURE_PROFILE_TYPE {
ProfileInvalid = 0x0000,
ProfileNonRemovableDisk = 0x0001,
ProfileRemovableDisk = 0x0002,
ProfileMOErasable = 0x0003,
ProfileMOWriteOnce = 0x0004,
ProfileAS_MO = 0x0005,
// Reserved 0x0006 - 0x0007
ProfileCdrom = 0x0008,
ProfileCdRecordable = 0x0009,
ProfileCdRewritable = 0x000a,
ProfileDvdRom = 0x0010,
ProfileDvdRecordable = 0x0011,
ProfileDvdRam = 0x0012,
ProfileDvdRewritable = 0x0013,
ProfileDvdRWSequential = 0x0013,
// Reserved - 0x0014,
ProfileDvdPlusRW = 0x001a,
// Reserved - 0x001b,
ProfileDDCdrom = 0x0020,
ProfileDDCdRecordable = 0x0021,
ProfileDDCdRewritable = 0x0022,
// Reserved - 0x0023,
ProfileNonStandard = 0xffff
} FEATURE_PROFILE_TYPE, *PFEATURE_PROFILE_TYPE;

And the Data is FEATURE_HEADER struct:

typedef struct _FEATURE_HEADER {
UCHAR FeatureCode[2];
UCHAR Current:1;
UCHAR Persistent:1;
UCHAR Version:3;
UCHAR Reserved0:2;
UCHAR AdditionalLength;
} FEATURE_HEADER, *PFEATURE_HEADER;

Where FeatureCode is an enumerator value of type FEATURE_NUMBER:

typedef enum _FEATURE_NUMBER {
FeatureProfileList = 0x0000,
FeatureCore = 0x0001,
FeatureMorphing = 0x0002,
FeatureRemovableMedium = 0x0003,
FeatureWriteProtect = 0x0004,
// Reserved 0x0005 - 0x000f
FeatureRandomReadable = 0x0010,
// Reserved 0x0011 - 0x001c
FeatureMultiRead = 0x001d,
FeatureCdRead = 0x001e,
FeatureDvdRead = 0x001f,
FeatureRandomWritable = 0x0020,
FeatureIncrementalStreamingWritable = 0x0021,
FeatureSectorErasable = 0x0022,
FeatureFormattable = 0x0023,
FeatureDefectManagement = 0x0024,
FeatureWriteOnce = 0x0025,
FeatureRestrictedOverwrite = 0x0026,
FeatureCdrwCAVWrite = 0x0027,
FeatureMrw = 0x0028,
// Reserved - 0x0029
FeatureDvdPlusRW = 0x002a,
// Reserved - 0x002b
FeatureRigidRestrictedOverwrite = 0x002c,
FeatureCdTrackAtOnce = 0x002d,
FeatureCdMastering = 0x002e,
FeatureDvdRecordableWrite = 0x002f,
FeatureDDCDRead = 0x0030,
FeatureDDCDRWrite = 0x0031,
FeatureDDCDRWWrite = 0x0032,
// Reserved 0x0030 - 0x00ff
FeaturePowerManagement = 0x0100,
FeatureSMART = 0x0101,
FeatureEmbeddedChanger = 0x0102,
FeatureCDAudioAnalogPlay = 0x0103,
FeatureMicrocodeUpgrade = 0x0104,
FeatureTimeout = 0x0105,
FeatureDvdCSS = 0x0106,
FeatureRealTimeStreaming = 0x0107,
FeatureLogicalUnitSerialNumber = 0x0108,
// Reserved = 0x0109,
FeatureDiscControlBlocks = 0x010a,
FeatureDvdCPRM = 0x010b
// Reserved 0x010c - 0xfeff
// Vendor Unique 0xff00 - 0xffff
} FEATURE_NUMBER, *PFEATURE_NUMBER;

All these structs kind of confuse me...
Nov 17 '05 #3
Hi,
For P/Invoke signatures you should take a look at www.pinvoke.net

And please if the one you are looking for is not there and you do it by
yourself just try your best and update the site back :)

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Mads Tjørnelund Toustrup" <Ma*******************@discussions.microsoft.com >
wrote in message news:41**********************************@microsof t.com...
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 _GET_CONFIGURATION_HEADER {
UCHAR DataLength[4];
UCHAR Reserved[2];
UCHAR CurrentProfile[2];
UCHAR Data[0];
} GET_CONFIGURATION_HEADER, *PGET_CONFIGURATION_HEADER;

Taken from this site:
http://msdn.microsoft.com/library/de...6a488c.xml.asp

I hope there is a helpful soul out there who can help me out?

Nov 17 '05 #4


"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
For P/Invoke signatures you should take a look at www.pinvoke.net

And please if the one you are looking for is not there and you do it by
yourself just try your best and update the site back :)

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Mads Tjørnelund Toustrup" <Ma*******************@discussions.microsoft.com >
wrote in message news:41**********************************@microsof t.com...
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 _GET_CONFIGURATION_HEADER {
UCHAR DataLength[4];
UCHAR Reserved[2];
UCHAR CurrentProfile[2];
UCHAR Data[0];
} GET_CONFIGURATION_HEADER, *PGET_CONFIGURATION_HEADER;

Taken from this site:
http://msdn.microsoft.com/library/de...6a488c.xml.asp

I hope there is a helpful soul out there who can help me out?


That's a great starting place, but ufortunately GET_CONFIGURATION_HEADER is
not there...
Nov 17 '05 #5
Hi,

Well be nice with the community and post it yourself :)
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


That's a great starting place, but ufortunately GET_CONFIGURATION_HEADER
is
not there...

Nov 17 '05 #6
> All these structs kind of confuse me...

Well FEATURE_HEADER translates to something like

struct FEATURE_HEADER
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public byte[] FeatureCode;
public byte Current_Persistent_Version;
public byte AdditionalLength;
}

You'll have to manually extract the components of the bitfield (Current,
Persistent, Version) using the bitwise operators.

The enums can almost be used as is, just remove the typedef stuff.
Mattias

Nov 17 '05 #7
I dont't really follow you on "extracting the components of the bitfield
using the bitwise operators..."?

"Mattias Sjögren" wrote:
All these structs kind of confuse me...


Well FEATURE_HEADER translates to something like

struct FEATURE_HEADER
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=2)]
public byte[] FeatureCode;
public byte Current_Persistent_Version;
public byte AdditionalLength;
}

You'll have to manually extract the components of the bitfield (Current,
Persistent, Version) using the bitwise operators.

The enums can almost be used as is, just remove the typedef stuff.
Mattias

Nov 17 '05 #8
I dont't really follow you on "extracting the components of the bitfield
using the bitwise operators..."?


'Current' is represented by bit 0 in the byte field. To check it you
simply do

current = featureHeader.Current_Persistent_Version & 0x1;

'Version' is stored in bits 2-4 and to read that you do

version = (featureHeader.Current_Persistent_Version >> 2) & 0x7;
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #9

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: Jacky | last post by:
Hi, I am trying to make network card interface with VB.NET 2002. I use DeviceIOControl-function. I have tried to define inbuffer and outbuffer using byte array and it's pointer. The second I...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.