• Windows核心编程:第1章 错误处理


    Github

    https://github.com/gongluck/Windows-Core-Program.git

    //第1章 错误处理.cpp: 定义应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include "第1章 错误处理.h"
    
    int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
    	_In_opt_ HINSTANCE hPrevInstance,
    	_In_ LPWSTR    lpCmdLine,
    	_In_ int       nCmdShow)
    {
    	HANDLE hFile = CreateFile(TEXT("C:\gongluck"), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
    	DWORD err = GetLastError();;
    	HLOCAL hlocal = NULL;
    	if (err != ERROR_SUCCESS)
    	{
    		//将错误码(可指定自然语言)格式化输出
    		DWORD res = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
    			NULL,
    			err,
    			MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
    			(LPTSTR)&hlocal,
    			0,
    			NULL);
    		MessageBox(NULL, (PCTSTR)hlocal, TEXT("err"), MB_OK);
    	}
    
    	//FormatMessage的格式化输出功能
    	int nYear = 2018, nMonth = 5, nDay = 22;
    	TCHAR szYear[5], szMonth[3], szDay[3];
    	wsprintf(szYear, TEXT("%d"), nYear);
    	wsprintf(szMonth, TEXT("%d"), nMonth);
    	wsprintf(szDay, TEXT("%d"), nDay);
    	LPWSTR lpSource = (LPWSTR)TEXT("今天是:%1年%2月%3日");
    	DWORD_PTR pArgs[] = { (DWORD_PTR)szYear, (DWORD_PTR)szMonth, (DWORD_PTR)szDay };
    	const DWORD size = 100 + 1;
    	WCHAR buffer[size];
    	if (FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
    		lpSource,
    		NULL,
    		NULL,
    		buffer,
    		size,
    		(va_list*)pArgs))
    	{
    		MessageBox(NULL, buffer, TEXT("Date"), MB_ICONINFORMATION);
    	}
    	//
    	system("pause");
    	return 0;
    }
    
  • 相关阅读:
    3.1C#中的命名空间
    2章总结
    2.4冒泡排序
    2.3 C#中的数组
    2.2二重循环
    2.1c#中的循环语句
    1章总结
    docker内外数据拷贝
    搭建docker环境
    centos7 部署Apache的httpd服务器
  • 原文地址:https://www.cnblogs.com/gongluck/p/9080191.html
Copyright © 2020-2023  润新知