Like Tree1Likes
  • 1 Post By _Mike

Device IO

This is a discussion on Device IO within the Windows Programming forums, part of the Platform Specific Boards category; Is there a way I can open a device using CreateFile and the device's physical device name ( such as: ...

  1. #1
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69

    Post Device IO

    Is there a way I can open a device using CreateFile and the device's physical device name ( such as: \Device\000055 )? What would all the arguments to CreateFile be?
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    CreateFile Function (Windows)

    Google is your friend!

  3. #3
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    I have tried but it comes up with the error "file not found".
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    I have tried but it comes up with the error "file not found".
    Are you formatting the drive name correctly?

    In C, as a physical drive, named in a string literal you need "\\\\.\\PhysicalDrive0" to open drive C: You have to double the slashes because C uses the \ as an escape character like in \n ... so to get one slash you need 2.

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Naming Files, Paths, and Namespaces (Windows)
    Quote Originally Posted by MSDN
    NT Namespaces

    There are also APIs that allow the use of the NT namespace convention, but the Windows Object Manager makes that unnecessary in most cases. To illustrate, it is useful to browse the Windows namespaces in the system object browser using the Windows Sysinternals WinObj tool. When you run this tool, what you see is the NT namespace beginning at the root, or "\". The subfolder called "Global??" is where the Win32 namespace resides. Named device objects reside in the NT namespace within the "Device" subdirectory. Here you may also find Serial0 and Serial1, the device objects representing the first two COM ports if present on your system. A device object representing a volume would be something like "HarddiskVolume1", although the numeric suffix may vary. The name "DR0" under subdirectory "Harddisk0" is an example of the device object representing a disk, and so on.

    To make these device objects accessible by Windows applications, the device drivers create a symbolic link (symlink) in the Win32 namespace, "Global??", to their respective device objects. For example, COM0 and COM1 under the "Global??" subdirectory are simply symlinks to Serial0 and Serial1, "C:" is a symlink to HarddiskVolume1, "Physicaldrive0" is a symlink to DR0, and so on. Without a symlink, a specified device "Xxx" will not be available to any Windows application using Win32 namespace conventions as described previously. However, a handle could be opened to that device using any APIs that support the NT namespace absolute path of the format "\Device\Xxx".
    If the device has a symlink in the Global?? namespace you can open it with CreateFile (with the symlink name, not the device path) assuming you have the correct user rights to open it.
    If not then you have to use the NT api, like NtCreateFile, etc..
    Salem likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Electronic device
    By stevesmithx in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-29-2008, 12:40 PM
  2. /device/phisicalmemory
    By nvms in forum Windows Programming
    Replies: 2
    Last Post: 03-05-2008, 07:17 PM
  3. Replies: 4
    Last Post: 06-30-2004, 04:11 PM
  4. device drivers i/o
    By datainjector in forum C Programming
    Replies: 2
    Last Post: 12-16-2002, 05:49 PM
  5. MCI device
    By The15th in forum Windows Programming
    Replies: 1
    Last Post: 10-19-2001, 11:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21