Tips for using Win32 Device Namespaces in APIs

stars-and-space-through-a-window

Win32 Device Namespaces

Device Access: \\.\

Similar to working with the files in /dev on a *nix system, use the “\\.\” prefix to access Win32 device namespaces instead of the standard Win32 file namespace that you get using single backslashes. Remember that you’re just specifying a handle, or an index to something in the kernel. A device could be specified for lpFileName to access a physical disk, for instance.

HANDLE WINAPI CreateFile(
  __in      LPCTSTR lpFileName,
  __in      DWORD dwDesiredAccess,
  __in      DWORD dwShareMode,
  __in_opt  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  __in      DWORD dwCreationDisposition,
  __in      DWORD dwFlagsAndAttributes,
  __in_opt  HANDLE hTemplateFile
);

However, this is definitely implementation specific. You know the drill — be prepared for microsoft to pull the rug out from under your feet by changing the implementation in any service pack or update.

Escape Parsing: \\?\

For file I/O, the “\\?\” prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system. The \\?\ can be a tricky one to work it as some APIs may not support it.

Posted by admica   @   13 September 2010

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

*

Previous Post
«
Next Post
»
Powered by Wordpress   |   Lunated designed by ZenVerse

Valid XHTML 1.0 Transitional