#include #include #include #include #include // Max handles program int __cdecl wmain(int, wchar_t**) { std::vector handles; std::wostringstream stream; std::wstring tempPath(GetTempPathW(0, NULL), 0); GetTempPathW(tempPath.size(), &tempPath[0]); tempPath.resize(tempPath.size() - 1); handles.reserve(600000); DWORD error = 0; for(DWORD i = 1; INFINITE; ++i) { stream.str(L""); stream << tempPath << L"\\tempFile" << i; HANDLE hFile = CreateFileW( stream.str().c_str(), DELETE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE | FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_NO_BUFFERING, NULL ); if(hFile == INVALID_HANDLE_VALUE) { error = GetLastError(); break; } if((i % 2000) == 0) { std::cout << i << " files created\r"; } handles.push_back(hFile); } std::cout << "\nCreated " << handles.size() << " files before getting error " << error << std::endl; std::for_each(handles.begin(), handles.end(), &CloseHandle); return 0; }