#pragma once #include //#include "TmplBlockBuffer.tlh" //#include "TmplBlockBuffer.tli" // 通过调用 FormtMessage, 把 Win32 错误码转换成字符串 inline std::string ErrorCodeToString (DWORD errorCode) { std::string rc; if (errorCode == 0) errorCode = GetLastError (); std::string fs = std::to_string (errorCode); rc += " : "; const int nPreAlloc = 2048; //ECOM::Utility::TmplUniqueBuffer errmsg; // auto pszBuffer = errmsg.GetBufferSetCount (nPreAlloc); std::string errmsg; errmsg.reserve (nPreAlloc); auto pszBuffer = errmsg.data (); auto len = ::FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorCode, // GetLastError (), MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) pszBuffer, nPreAlloc, NULL); rc.append (pszBuffer, len - 2); // -2 : 目的是删除尾部的回车/换行 return std::move (rc); }