Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > Best way to use IOCTLs only supported on some Windows versions

Reply
Fix Vista Errors
Thread Tools Display Modes

Best way to use IOCTLs only supported on some Windows versions

 
 
Maël Hörz
Guest
Posts: n/a

 
      10-22-2009



Hello,

What is the best way to use IOCTLs only supported on some Windows versions?

For example calling DeviceIoControl with
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX is only supported on Windows XP and
upwards.

Should I test if I am on at least Windows XP before calling
DeviceIoControl with IOCTL_DISK_GET_DRIVE_GEOMETRY_EX or should I simply
call DeviceIoControl and see if it fails (and fall back to
IOCTL_DISK_GET_DRIVE_GEOMETRY in this case)?

Regards, Maël Hörz
 
Reply With Quote
 
David Craig
Guest
Posts: n/a

 
      10-22-2009
That is a philosophical question. If the IoCtl 'works' in that is doesn't
cause a major failure and will not be issued very often, then choose #2. If
you want to improve speed then check OS version and call the correct
function. You can use function pointers that point to one of two functions
that use either the EX or normal call and initialize them during startup
(DriverEntry, AddDevice, or start as appropriate). This would cut the
decision points to one and keep runtime code cleaner. You can even always
use the EX data and have the older call routine convert the structure to the
EX format in that routine so the remainder of the code only has to worry
about one data type. If there is missing data the older call does not
provide make sure you don't trip over it when it is missing or just compute
it if you need to do so.

This is something that should be designed in to the driver/application early
on depending upon your requirements. A good architect will write these
types of design decisions in the specifications. That being said very few of
us have an architect but do it ourselves.


"Maël Hörz" <> wrote in message
news:O6n%...
> Hello,
>
> What is the best way to use IOCTLs only supported on some Windows
> versions?
>
> For example calling DeviceIoControl with IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
> is only supported on Windows XP and upwards.
>
> Should I test if I am on at least Windows XP before calling
> DeviceIoControl with IOCTL_DISK_GET_DRIVE_GEOMETRY_EX or should I simply
> call DeviceIoControl and see if it fails (and fall back to
> IOCTL_DISK_GET_DRIVE_GEOMETRY in this case)?
>
> Regards, Maël Hörz



 
Reply With Quote
 
Maël Hörz
Guest
Posts: n/a

 
      10-23-2009
I'm asking this question because for Win32 API functions, that may not
be supported by all target operating systems, the common recommendation
is to use LoadLibrary&GetProcAddress to see if the function is available.

In that case the advice is because a service pack or some
redistributable might update the OS and thereby provide a missing API
even if the OS version (at least major and minor version numbers) stays
the same.

So what I really want to know is if it safe to call DeviceIoControl if
the control code is potentially unsupported or if it can cause problems
(except returning false). Or if there is something similar to
GetProcAddress for IOCTLs.
 
Reply With Quote
 
Maël Hörz
Guest
Posts: n/a

 
      10-23-2009
> This is something that should be designed in to the driver/application early
> on depending upon your requirements. A good architect will write these
> types of design decisions in the specifications. That being said very few of
> us have an architect but do it ourselves.

I'm the only developer of the application and have been thinking about
this again when reviewing old code. W.r.t. the requirements speed is not
a very big issue because I'm doing this only once during initialization
and then store the information for later use.
 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a

 
      10-24-2009
Maël Hörz <> wrote:
>
>So what I really want to know is if it safe to call DeviceIoControl if
>the control code is potentially unsupported or if it can cause problems
>(except returning false). Or if there is something similar to
>GetProcAddress for IOCTLs.


A few moments thought about how ioctls work should have answered your
second question.

In general, you should just submit the ioctl and check for an error.
Unsupported is the best case. The worst case is if the ioctl code is
assigned for some other use. Fortunately, that almost never happens with
Microsoft drivers.
--
Tim Roberts,
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
Maxim S. Shatskih
Guest
Posts: n/a

 
      10-25-2009
> What is the best way to use IOCTLs only supported on some Windows versions?

Only use the oldest IOCTL still supported on the oldest Windows version from your requirements.

--
Maxim S. Shatskih
Windows DDK MVP

http://www.storagecraft.com

 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Vista Ultimate upgrade hangs on install DazL Windows Vista Installation 2 02-22-2008 02:12 AM
Installer Issue Jimbo Windows Vista Installation 4 08-15-2007 03:06 PM
Vista Boot Files Daarrheel Windows Vista Installation 9 08-09-2007 12:18 AM
Corrupt Files juerg Windows Vista Installation 10 07-12-2007 05:38 PM
windows stopped booting... Karim Windows Vista Installation 1 06-19-2007 09:16 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59