I'm using the following code to get the filepath to save to for use with tinyxml2:
OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFilter = (LPCWSTR)L"XML Files (*.xml)\0*.xml\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = (LPWSTR)szFileName;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = (LPCWSTR)L"xml";
GetSaveFileName(&ofn);
This works fine and displays the Dialog box however when I look up the returned value in szFileName it seems to contain many null characters:
szFileName 0x0026f5b0 "C" char[0x00000104]
[0x00000000] 0x43 'C' char
[0x00000001] 0x00 '\0' char
[0x00000002] 0x3a ':' char
[0x00000003] 0x00 '\0' char
[0x00000004] 0x5c '\\' char
[0x00000005] 0x00 '\0' char
[0x00000006] 0x61 'a' char
[0x00000007] 0x00 '\0' char
[0x00000008] 0x73 's' char
[0x00000009] 0x00 '\0' char
[0x0000000a] 0x64 'd' char
[0x0000000b] 0x00 '\0' char
[0x0000000c] 0x61 'a' char
[0x0000000d] 0x00 '\0' char
[0x0000000e] 0x73 's' char
[0x0000000f] 0x00 '\0' char
[0x00000010] 0x64 'd' char
[0x00000011] 0x00 '\0' char
[0x00000012] 0x61 'a' char
[0x00000013] 0x00 '\0' char
[0x00000014] 0x73 's' char
[0x00000015] 0x00 '\0' char
[0x00000016] 0x2e '.' char
[0x00000017] 0x00 '\0' char
[0x00000018] 0x78 'x' char
[0x00000019] 0x00 '\0' char
[0x0000001a] 0x6d 'm' char
[0x0000001b] 0x00 '\0' char
[0x0000001c] 0x6c 'l' char
This when passed into tinyxml2 ends up saving a file with which the name is 1 character long, and the first char in szFileName.
Why would it be adding in these null characters after each character?
(LPWSTR)szFileName
is a very very very very very very very very very very very very bad thing to do.