VS2015, Unicode: Getting the "Could Not Find the Path Specified" error running the following code in a listbox:
wchar_t *currPath, *cumPath;
int listTotal = 5;
int pathLength = 32760;
listTotal = SendMessageW(hList, LB_GETCOUNT, 0, 0);
wcscpy_s(cumPath, pathLength, L"\\?\C:");
//wcscpy_s(cumPath, pathLength, L"C:"); //Tried this, no difference
wcscpy_s(currPath, MAX_PATH - 3, L"");
for (int i = 0; i < listTotal; i++) {
SendMessageW(hList, LB_GETTEXT, i, (LPARAM) currPath); //"My Nested Path" picked up from textbox OK
wcscat_s(cumPath, pathLength, (wchar_t *) currPath);
\OK but doubled backslashes
wcscat_s(cumPath, MAX_PATH - 3, __TEXT(""));
\appear in debugger variable contents
}
int errorcode = CreateDirectoryW(cumPath, NULL);
if (errorcode == 0) {
ErrorExit(TEXT("CreateDirectoryW"));
//GetLastError courtesy [MSDN][1]
}
Meh, have I missed something fundamental here?
The double backslash is not parsed out of the variable name. Is there a way to construct a macro using a verbatim or "as is" prefix that works in conjunction with TEXT or L?
Edit1 The following two lines preceded the code:
currPath = (wchar_t *)calloc(pathLength, sizeof(wchar_t));
cumPath = (wchar_t *)calloc(pathLength, sizeof(wchar_t));
Both these vars are declared module wide. However, prior to entry on this sub there was:
currPath = (wchar_t *)calloc(pathLength, sizeof(wchar_t));
...
free(currPath);
Would the "re-calloc" of currPath have upset anything?
Edit2: No, tried with another variable. The value of cumPath before CreateDirectoryW is as expected?
cumPath = 0x005b4fe8 L"\\?\C:\My Nested Path\My Nested Path\My Nested Path\My Nested Path\My Nested Path"
Eureka! commenting out this line, the function worked!
//wcscat_s(cumPath, MAX_PATH - 3, __TEXT(""));
But now there are no nested directories, as was the original requirement.
cumPath = 0x00644fe8 L"\?C:My Nested PathMy Nested PathMy Nested PathMy Nested PathMy Nested Path"
See Question&Answers more detail:
os