#include <windows.h>#include <ktmw32.h>#include <stdio.h>#include <stdlib.h>#include <tchar.h>#include <strsafe.h>int __cdecl _tmain(int argc, TCHAR ** argv){ HANDLE hTrans; HANDLE hFile; DWORD dwFileNum; TCHAR szFileName[MAX_PATH]; // Create the transaction. hTrans = CreateTransaction(NULL, NULL, 0, 0, 0, 0, NULL); if (hTrans == INVALID_HANDLE_VALUE) { _tprintf(_T("Could not create transaction.\n")); return EXIT_FAILURE; } // Currently, we're still operating as a normal, non-transacted // thread. To use the transaction we've just created, call // SetCurrentTransaction. if (!SetCurrentTransaction(hTrans)) { _tprintf(_T("Could not change transactions.\n")); return EXIT_FAILURE; } dwFileNum = 1; while (TRUE) { StringCchPrintf(szFileName, sizeof(szFileName)/sizeof(szFileName[0]), _T("%i"), dwFileNum); hFile = CreateFile(szFileName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { _tprintf(_T("Failed to create file number %i, GLE %i\n"), dwFileNum, GetLastError()); if (!RollbackTransaction(hTrans)) { _tprintf(_T("Failed to rollback transaction\n")); } CloseHandle(hTrans); if (!SetCurrentTransaction(NULL)) { _tprintf(_T("Could not switch back to non-transactional state.\n")); } return EXIT_SUCCESS; } dwFileNum++; if (dwFileNum % 10000 == 0) { _tprintf(_T("%i\n"), dwFileNum); } } return EXIT_SUCCESS;}