写入:
iLength = lstrlen(szUsrName);
WriteFile(hFile, &iLength, sizeof(int), &dwValue, NULL);
WriteFile(hFile, &szUsrName, (int)iLength, &dwValue, NULL);
读取:
ReadFile(hFile, &iLength, sizeof(int), &dwValue, NULL);
ReadFile(hFile, &szUsrName, iLength, &dwValue, NULL);
szUsrName[iLength] = '\0';其中,TCHAR szUsrName[MAX_PATH];ANSI程序,则没有任何问题,可以正常写入,也可以正常读出。
但编译成Unicode,则不行。不能正确写入,也不能正确读出。