Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Win32
Hi, I have tried some code ejecting CD ROM drive and one of the functions is CreateFile, the first argument of it is filename. At first I passed in "F:" (my cd rom drive letter) only, and there was an error with error code of 21 (device is not ready), I rechecked the sample code and I should've passed in @"\\.\F:" so what is the string "\\.\F:"?
 
Your help would be highly appreciated! Thanks!
Posted 17-Sep-12 6:30am
supernorb2.6K
Comments
Wes Aday at 17-Sep-12 11:52am
   
"@"\\.\F:"... there is the clue. The \\. is a UNC path to the local machine and does not make any sense. \F: is the path to the F drive. So @"\\.\F:" is the same thing as @"\F:"
losmac at 17-Sep-12 12:43pm
   
My virtual 5!
supernorb at 17-Sep-12 13:05pm
   
I don't know what UNC path is, but "\\.\F:" does really make sense in my case, the CreateFile function can be executed successfully with it passed in as the first argument (filename) but not with "F:" (which is the most meaningful ???) passed in!
I don't think they are the same, of course at least to the way CreateFile works!
Wes Aday at 17-Sep-12 13:14pm
   
It actually means exactly what I told you it means. The reason that you have to put the UNC path in the string is clearly identified in the documentation, "to call the Unicode version ...". All strings are natively unicode in .NET
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm not sure you can use CreateFile to write to a CD-ROM (people are still using those?). But "\\.\F:" doesn't make sense. "\\." would be the root of the current drive, probably "C:\", and "F:" would point to your F drive, but putting them together doesn't work (you'd be going to C:\F:\, which is invalid).
 
Not to mention the first "\" is escaped, and the second is not, so depending on whether the string is using an @ or not (i.e. @"\\.\F:") you could also be going to C:\\F: (a nameless directory, not allowed by Windows to my knowledge, then a drive inside that which is invalid), or the F is a control character (form feed I think?) which should be invalid in Windows paths as well.
 
So to summarize, it doesn't mean anything.
 
On the other hand, your error is probably popping up because you use CreateFile, and then give it a path to a drive. You need to give it a path to a file, e.g. "F:\\myfile.ext".
  Permalink  
Comments
Wes Aday at 17-Sep-12 11:50am
   
Could also mean a UNC path. But a UNC path to the local machine does not make much sense either.
lewax00 at 17-Sep-12 11:56am
   
Yeah the command line spit an error about that when I tried to use it as a path, I'm not sure what a UNC path is but I did get that Windows didn't like it...and now I'm off to Google to learn. (Edit: never mind, I've used those before, just didn't know the name...)
Wes Aday at 17-Sep-12 12:18pm
   
Lol... well good that you were at least willing to look it up instead of posting it as a QA question... :-)
lewax00 at 17-Sep-12 12:22pm
   
But if I use Google instead, how will I ever become a platinum enquirer?! :P
Wes Aday at 17-Sep-12 12:24pm
   
Would not bother me a bit if I never ever got platinum for that one. In fact, I am rather surprised that I have platinum at all in anything.
supernorb at 17-Sep-12 12:58pm
   
Please read my question carefully, If I passed the "F:" in, it would say "The device is not ready", but if I passed the @"\\.\F:" in, the CreateFile would excute successfully and return a handle to the drive F which I call "Drive handle", this is then passed into the API function DeviceIoControl, (I'm talking about my CD Ejector application).
Thanks!
lewax00 at 17-Sep-12 13:02pm
   
Regardless, as a normal path it makes no sense. I may be something special for that function, read the documentation for it (I did see mention of "\\?\" but not "\\.\"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

CreateFile has many uses beyond creating and opening files. Passing a string such as "\\.\F:" opens a logical drive so that DeviceIO functions can be used.
 
See http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx[^]
 
Alan.
  Permalink  
Comments
supernorb at 17-Sep-12 13:01pm
   
Yeah, you are right, but could you please be more elaborated on the meaning of "\\.\F:", I really don't understand what it is? (Of course the "F:" is my CD drive, but what about the prefix???)!
Thank you so much, you deserve my click on the accept solution button!
lewax00 at 17-Sep-12 13:28pm
   
From the page he linked to: "When opening a volume or removable media drive (for example, a floppy disk drive or flash memory thumb drive), the lpFileName string should be the following form: "\\.\X:". Do not use a trailing backslash (\), which indicates the root directory of a drive."
 
There's your answer, it's just used to tell the function you're opening a drive. It has no meaning on its own, just in the context of the function.
supernorb at 18-Sep-12 9:58am
   
Yeah, thanks, I thought it can be used somewhere else

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100