The MSDN page on CreateFile says: The string "\\.\C:\" can be used to open the file system of the C: volume. However, the following code always returns an error : ERROR_PATH_NOT_FOUND.
HANDLE h = CreateFile(L"\\\\.\\C:\\", FILE_READ_ATTRIBUTES,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 0, OPEN_EXISTING, 0, 0);
How should I pass the arguments correctly?
If you wanted a volume handle (for use with I/O control codes) you would have needed to drop the trailing slash.
In order to get a handle to the root directory, you need to keep the trailing slash and pass the
FILE_FLAG_BACKUP_SEMANTICSflag in thedwFlagsAndAttributesargument. This is documented on the MSDN page under the heading “Directories”. For example, this is what you want to do if you’re planning to callGetFileInformationByHandleorGetFileInformationByHandleEx.Ordinarily, however, you wouldn’t open a handle to the root directory in order to list the files. Instead, you would use
FindFirstFile/FindNextFileor one of the related functions.