Win32显示系统调用失败后的错误信息

DWORD ShowSystemError(HWND hwndMsgOwner)
{
	DWORD dwError = GetLastError();
	HLOCAL hlocal = NULL;
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
		NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), (TCHAR*)&hlocal, 0, NULL);
	MessageBox(hwndMsgOwner, (TCHAR*)LocalLock(hlocal), 0, 0);
	LocalFree(hlocal);
	return dwError;
}
void ShowSystemError(HWND hwndMsgOwner, DWORD dwError)
{
	HLOCAL hlocal = NULL;
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
		NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), (TCHAR*)&hlocal, 0, NULL);
	MessageBox(hwndMsgOwner, (TCHAR*)LocalLock(hlocal), 0, 0);
	LocalFree(hlocal);
}
//要调用setlocale(LC_ALL,"chs");
void ShowSystemError(DWORD dwError)
{
	HLOCAL hlocal = NULL;
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
		NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), (TCHAR*)&hlocal, 0, NULL);
	_tprintf(_T("%s"), (TCHAR*)LocalLock(hlocal));
	LocalFree(hlocal);
}

你可能感兴趣的:(Win32,Windows)