// SambaTest.cpp : Defines the entry point for the console application. // #include #include int main(int argc, char* argv[]) { int result = 1; char filename[] = "testfile.tmp"; FILETIME ft; SYSTEMTIME st; HANDLE hFile = INVALID_HANDLE_VALUE; HANDLE hFindFile = INVALID_HANDLE_VALUE; WIN32_FIND_DATA fd; // Create new file hFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) { goto End; } printf("Created file %s\n", filename); // set to 1.1.2005 00:00 ZeroMemory(&st, sizeof(st)); st.wDay = 1; st.wMonth = 1; st.wYear = 2005; if (!(SystemTimeToFileTime(&st, &ft) && SetFileTime(hFile, 0, 0, &ft))) { goto End; } printf("Set filetime (UTC) to %2.2d.%2.2d.%4.4d %2.2d:%2.2d\n", st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute); // Close file CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; printf("Closed file %s\n\n", filename); // Open existing file hFindFile = FindFirstFile(filename, &fd); if (hFindFile == INVALID_HANDLE_VALUE) { FindClose(hFindFile); goto End; } FindClose(hFindFile); printf("Found file %s\n", filename); // read and convert file time if (!FileTimeToSystemTime(&fd.ftLastWriteTime, &st)) { goto End; } printf("Read filetime (UTC): %2.2d.%2.2d.%4.4d %2.2d:%2.2d\n", st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute); result = 0; End: if (hFile != INVALID_HANDLE_VALUE) { CloseHandle(hFile); printf("Closed file %s\n\n", filename); } if (result != 0) { printf("Error\n"); } printf("\nHit to terminate\n"); getchar(); }