当前位置: 首页>>代码示例>>C++>>正文


C++ TextFile::create方法代码示例

本文整理汇总了C++中TextFile::create方法的典型用法代码示例。如果您正苦于以下问题:C++ TextFile::create方法的具体用法?C++ TextFile::create怎么用?C++ TextFile::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextFile的用法示例。


在下文中一共展示了TextFile::create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sizeof

void	PrintCallStackOfThisThread(const wchar_t* name, const wchar_t* expression, const wchar_t* function, const wchar_t* file, int line)
{
	if (name == NULL) name = L"Unknown";
	if (expression == NULL) expression = L"No Expression";
	if (function == NULL) function = L"Unknown Function";
	if (file == NULL) file = L"Unknown File";

	wchar_t folder[MAX_PATH] = { 0, };
	GetProcessFolder(::GetCurrentProcess(), folder, _countof(folder));

	wchar_t callStackFile[MAX_PATH] = { 0, };

	SYSTEMTIME systemTime;
	::memset(&systemTime, 0, sizeof(systemTime));
	::GetLocalTime(&systemTime);

	::swprintf_s(callStackFile, _countof(callStackFile), L"%s/%s_%04d-%02d-%02d.rpt",
		folder, name, systemTime.wYear, systemTime.wMonth, systemTime.wDay);

	TextFile textFile;

	int count = 0;
	while (textFile.open(callStackFile, GENERIC_WRITE, FILE_SHARE_READ) == false &&
		textFile.create(callStackFile, GENERIC_WRITE, FILE_SHARE_READ) == false)
	{
		++count;

		::swprintf_s(callStackFile, _countof(callStackFile), L"%s/%s_%04d-%02d-%02d(%d).rpt",
			folder, name, systemTime.wYear, systemTime.wMonth, systemTime.wDay, count);
	}

	textFile.seek(0, FILE_END);

	DumpPrint(&textFile, L"[%04d-%02d-%02d %02d:%02d:%02d] %s at %s\r\n%s(%d)\r\n",
		systemTime.wYear, systemTime.wMonth, systemTime.wDay,
		systemTime.wHour, systemTime.wMinute, systemTime.wSecond,
		expression,
		function,
		file,
		line);

	// current thread call stack
	DWORD processId = ::GetCurrentProcessId();
	HANDLE process = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
	if (process != NULL)
	{
		HANDLE thread = ::GetCurrentThread();
		DWORD threadId = ::GetCurrentThreadId();

		DumpPrint(&textFile, L"%s(Thread(%u) Call Stack)\r\n", function, threadId);

		EXCEPTION_RECORD exceptionRecord = {};
		CONTEXT context = {};
		EXCEPTION_POINTERS exceptionPointers = { &exceptionRecord, &context };

		context.ContextFlags = CONTEXT_FULL;
		if (::GetThreadContext(thread, &context) != FALSE)
		{
			PrintThreadCallStack(&textFile, &exceptionPointers, process, thread);

			DumpPrint(&textFile, L"\r\n");
		}

		::CloseHandle(process);
		process = NULL;
	}

	DumpPrint(&textFile, L"\r\n");

	textFile.flush();
}
开发者ID:,项目名称:,代码行数:71,代码来源:


注:本文中的TextFile::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。