views:

86

answers:

2

In this document, http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#paths

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".

What are the APIs? Let me know some such functions please.

+1  A: 

The concept of treating a "device" as a "file" is common in *nix (Unix, Linux, Mac OS, etc).

Basically, the MSDN article means that any Win32 API that opens a "file" (either a local disk file, or a UNC resource) could just as easily open a "special device".

A couple of examples:

http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx

  CreateFile
  WriteFile
  ReadFile
  CloseHandle
CreateFileW(L"\\Device\\Xxx", ...) Is it possible? I don't think so.It must be a symbolic lick in GLOBAL?? namespace.
Benjamin
Look at the MSDN link I cited - I believe you'll find an example!Remember: "CreateFile()" is really pretty much a synonym for "open resource". It doesn't necessarily imply you're creating that resource from scratch.
But you do need to use a different syntax: \\.\device\Xxx.
Larry Osterman
@Larry It doesn't work. I can't open any device by the syntax. Does it work really?
Benjamin
Did you read the "Win32 Device Namespaces" part of the article you linked? Where did you get the device name you mentioned above?
Larry Osterman
What I said is, "\\.\C:" works but "\\.\Device\HarddiskVolume1" doesn't work.
Benjamin
You need to use the native API in order to open something in the \Device directory of the object manager namespace (Win32 restricts you to a subset of the namespace).
snoone
+1  A: 

Benjamin -

  1. The simple fact is that you CAN open a "special device file" in Windows, very much as you do in *nix. This is what I tried to say in my original reply. I stand by everything I said in my first post. And I believe the MSDN link I referred to there does a very good job of explaining this, too.

  2. The syntax for a *nix device file is "/dev/SOME_DEVICE". Multiple devices are (by convention, not necessity) distinguished as "/dev/SOME_DEVICE0", "/dev/SOME_DEVICE1", etc. Device files can also be "aliased" using *nix "symbolic links".

  3. The syntax for a Windows device file is a UNC name. I'm sure you're familiar with UNC shares (for example, "\\myserver\c$"). In all the examples we've discussed above, the server happens to be the local host. Hence "\\.\SOME_RESOURCE_NAME".

It's really as simple as that.

And it DOES work.

Please let me know if you have any further questions.

Thank you in advance .. PSM

Benjamin