新建一个控制台工程;代码;
// file.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
HANDLE hOutput;
void perro(LPTSTR pszTitle){
LPVOID pvErrMsg = NULL;
DWORD nError = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, nError,
MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED),
(LPTSTR)&pvErrMsg,
0, NULL);
TCHAR szText[256];
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
wsprintf(szText, "%s(errno=%d):%s\n", pszTitle, nError, (LPTSTR)pvErrMsg);
WriteConsole(hOutput, szText, wcslen(szText), NULL, NULL);
WriteConsole(hOutput, szText, 50, NULL, NULL);
LocalFree(pvErrMsg);
}
void Create()
{
HANDLE hFile = CreateFile(
_T("Y:/file.txt"), GENERIC_WRITE,
FILE_SHARE_READ, NULL, CREATE_ALWAYS,