On Thu, Apr 30, 2009 at 01:38:22PM +0200, Abdelrazak Younes wrote: > From what I read CreateFile (just like most other functions that take a > string param) is > nothing more than a macro that during precompilation expands to CreateFileA > or CreateFileW depending on the definition of UNICODE (when UNICODE is > defined it will expand to CreateFileW).
I have verified that this is also the case with mingw. Given that we don't define UNICODE, we are actually using the A version (but see below). > Hum, the problem is AFAIU that CreateFileA takes a 'char *' and > CreateFileW takes a 'wchar_t *' so I fear that we'll get a compilation > error on MSVC but I cannot test right now. I came across similar problem > recently while trying to dlopen a library by name... This is what I get when compiling the attached C program with UNICODE either defined or not: $ touch zzz $ gcc -mno-cygwin getfileinfo.c -o getfileinfo $ ./getfileinfo.exe zzz Volume: 1681330194 Index: 54473 $ gcc -mno-cygwin -DUNICODE getfileinfo.c -o getfileinfo getfileinfo.c: In function `main': getfileinfo.c:14: warning: passing arg 1 of `CreateFileW' from incompatible pointer type $ ./getfileinfo.exe zzz Cannot access "zzz" So, I think that it will be very clear if and when there will be problems. Moreover, note that toFileSystemEncoding() uses QFile::encodeName(), and this is what the Qt docs state about it: By default, this function converts \a fileName to the local 8-bit encoding determined by the user's locale. This is sufficient for file names that the user chooses. File names hard-coded into the application should only use 7-bit ASCII filename characters. Thus, we are doing the right thing, me thinks. -- Enrico
#include <stdio.h> #include <stdlib.h> #include <windows.h> int main(int argc, char **argv) { if (argc != 2) { printf("Usage: %s <filename>\n", argv[0]); exit(0); } // Open the file HANDLE h = CreateFile(argv[1], 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (h == INVALID_HANDLE_VALUE) { printf("Cannot access \"%s\"\n", argv[1]); exit(1); } // Get information BY_HANDLE_FILE_INFORMATION info; if (GetFileInformationByHandle(h, &info) == 0) { printf("Cannot get info for \"%s\"\n", argv[1]); exit(1); } CloseHandle(h); // Get the serial number of the volume containing the file. ULONG st_dev = info.dwVolumeSerialNumber; // Get the unique identifier associated to the file on the volume. ULONGLONG highbits = info.nFileIndexHigh & 0x0000FFFF; ULONGLONG st_ino = (highbits << sizeof(ULONG)) | info.nFileIndexLow; printf("Volume: %u\n", st_dev); printf("Index: %I64i\n", st_ino); return 0; }