CreateFileW failure
Philip Bock <
phil@...>
2005-06-02 17:38:53 GMT
I apologize if this is considered off-topic.
I'm writing a program that needs to be able to open files on network
shares with extremely long paths. Looking at MSDN, I see that if I use
the Unicode version of CreateFile, and prepend the string \\?\UNC to
the paths, I should be able to do this.
The problem is that my CreateFileW (unicode) call fails consistently with
error 123: The filename, directory name, or volume label syntax is
incorrect. If I use CreateFile (non-unicode), everything works as
expected, but of course my paths are limited to 260 characters.
I'm running this on Windows 2000 Server.
My test program is below. Both example filenames fail in the same way.
There is a C:\winzip.log, and my user has permission to access it. I
thought for a while my convert_to_unicode function might be the problem,
but the printf outputs an identical string for both versions, so I think
this is working.
Does anyone have any suggestions?
Thanks, Philip Bock
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
wchar_t *convert_to_unicode(const char *in) {
int c;
wchar_t *out = malloc(sizeof(wchar_t) * strlen(in));
for (c = 0; in[c]; c++)
out[c] = (wchar_t) in[c];
return out;
}
int main(int argc, char **argv) {
HANDLE f;
// char *filename = "\\\\?\\C:\\winzip.log";
char *filename = "\\\\?\\UNC\\127.0.0.1\C$\winzip.log";
wchar_t *wfilename = convert_to_unicode(filename);
printf("%s\n%ls\n", filename, wfilename);
/* Explicitly use Unicode to allow for long paths */
// f = CreateFile(filename, // Non-unicode: success
f = CreateFileW(wfilename, // Unicode: failure
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_FLAG_SEQUENTIAL_SCAN, // normal file
NULL); // no attr. template
free(wfilename);
if (f == INVALID_HANDLE_VALUE) { /* Failed to open source file */
printf("Failure: %lu\n", GetLastError());
}
else {
printf("Success!\n");
CloseHandle(f);
}
return 0;
}
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
MinGW-users mailing list
MinGW-users@...
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users