1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#ifdef _UNICODE
typedef wstring tstring;
#define to_tstring(x) to_wstring(x)
#else
typedef string tstring;
#define to_tstring(x) to_string(x)
#endif
const int bytesToSave = sizeof(int) * 2;
TCHAR path[MAX_PATH];
GetModuleFileName(NULL, path, MAX_PATH);
PathRemoveFileSpec(path);
tstring temp(path);
temp += _T("\\foo.txt");
HANDLE file = CreateFile(temp.c_str(), GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD written;
int save[2] = {
foo,
bar
};
if (!WriteFile(file, save, bytesToSave, &written, NULL)) {
DWORD errorCode = GetLastError();
tstring errorMessage = _T("Failed to save current status! Error Code: ");
errorMessage += to_tstring(errorCode);
MessageBox(hwnd, errorMessage.c_str(), _T("ERROR!"), MB_ICONERROR);
}
CloseHandle(file);
|