Article View: borland.public.cppbuilder.nativeapi
Article #4633Problem with DeviceIoControl() IOCTL_STORAGE_QUERY_PROPERTY
From: no.email
Date: Thu, 15 Dec 2005 23:54
Date: Thu, 15 Dec 2005 23:54
107 lines
4352 bytes
4352 bytes
I am attempting to retrieve the adapter properties of
GUID_DEVINTERFACE_CDROM devices. Just like is illustrated in the
enumcd.exe example of Microsoft
(http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q305184)
which has no problems getting the adapter properties on my development
system when I run the enclosed EXE.
However, when attempting to integrate microsoft's
IOCTL_STORAGE_QUERY_PROPERTY DeviceIoControl code into my C++ builder
project I am always getting "invalid parameter" when I execute the
DeviceIoControl.
Enumerating GUID_DEVINTERFACE_CDROM devices, getting a handle and
communicating with them (I send an Inquiry command) all work fine.
However, the IOCTL_STORAGE_QUERY_PROPERTY always fails.
An example :
DevicePath=\\?\ide#cdromhl-dt-st_dvd-rom_gdr8163b_______________0l23____#5&3001a662&0&0.1.0#{53f56308-b6bf-11d0-94f2-00a0c91efb8b}
CreateFile_Handle=790
ERROR::DeviceIoControl::IOCTL_STORAGE_QUERY_PROPERTY=GetLastError()=The
parameter is incorrect.
My code to send IOCTL_STORAGE_QUERY_PROPERTY looks like this :
...
Handle=CreateFile(
interfaceDetailData->DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,OPEN_EXISTING,0,NULL);
...
bool Status;
STORAGE_PROPERTY_QUERY query;
PSTORAGE_ADAPTER_DESCRIPTOR adpDesc;
UCHAR outBuf[512];
ULONG returnedLength;
query.PropertyId = StorageAdapterProperty;
query.QueryType = PropertyStandardQuery;
Status = DeviceIoControl(
Handle,
IOCTL_STORAGE_QUERY_PROPERTY,
&query,
sizeof(STORAGE_PROPERTY_QUERY),
&outBuf,
sizeof(outBuf),
&returnedLength,
NULL
);
if (!Status)
{
ShowError(); // GetLastError() + FormatMessage
}
However the request always fails with "The parameter is incorrect" and
I'm totally clueless about what I'm doing wrong. I cannot find any
obvious differences between my code and Microsoft's enumcd-example.
Just to be complete. These are the definitions I copied from
ntddstor.h in order to get everything compiled :
#define IOCTL_STORAGE_BASE FILE_DEVICE_MASS_STORAGE
#define IOCTL_STORAGE_QUERY_PROPERTY \
CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED,
FILE_ANY_ACCESS)
typedef enum _STORAGE_PROPERTY_ID {
StorageDeviceProperty = 0,
StorageAdapterProperty,
StorageDeviceIdProperty
} STORAGE_PROPERTY_ID, *PSTORAGE_PROPERTY_ID;
typedef enum _STORAGE_QUERY_TYPE {
PropertyStandardQuery = 0,
PropertyExistsQuery,
PropertyMaskQuery,
PropertyQueryMaxDefined
} STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE;
typedef struct _STORAGE_PROPERTY_QUERY {
STORAGE_PROPERTY_ID PropertyId;
STORAGE_QUERY_TYPE QueryType;
UCHAR AdditionalParameters[1];
} STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY;
#include <pshpack1.h>
typedef struct _STORAGE_ADAPTER_DESCRIPTOR {
ULONG Version;
ULONG Size;
ULONG MaximumTransferLength;
ULONG MaximumPhysicalPages;
ULONG AlignmentMask;
BOOLEAN AdapterUsesPio;
BOOLEAN AdapterScansDown;
BOOLEAN CommandQueueing;
BOOLEAN AcceleratedTransfer;
STORAGE_BUS_TYPE BusType;
USHORT BusMajorVersion;
USHORT BusMinorVersion;
} STORAGE_ADAPTER_DESCRIPTOR, *PSTORAGE_ADAPTER_DESCRIPTOR;
#include <poppack.h>
Any assistance is much appreciated,
Kris
Technical Details
Message-ID:
<8b04q11n406hs1bonf8n9586mn3of3lqm3@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f7af8c8a3ab6155a,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: no.email@mail.nl Newsgroups: borland.public.cppbuilder.nativeapi Subject: Problem with DeviceIoControl() IOCTL_STORAGE_QUERY_PROPERTY Date: Thu, 15 Dec 2005 15:54:21 -0800 Message-ID: <8b04q11n406hs1bonf8n9586mn3of3lqm3@4ax.com> X-Newsreader: Forte Free Agent 3.1/32.783 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 212.100.176.226 X-Trace: newsgroups.borland.com 1134651186 212.100.176.226 (15 Dec 2005 04:53:06 -0700) Lines: 107 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail