本文整理汇总了C++中FormatMessageA函数的典型用法代码示例。如果您正苦于以下问题:C++ FormatMessageA函数的具体用法?C++ FormatMessageA怎么用?C++ FormatMessageA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FormatMessageA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetModuleHandleA
Win32ErrorLogMessage::~Win32ErrorLogMessage()
{
const int error_message_buffer_size = 256;
char msgbuf[error_message_buffer_size];
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
HMODULE hmod;
if(module_)
{
hmod = GetModuleHandleA(module_);
if(hmod)
{
flags |= FORMAT_MESSAGE_FROM_HMODULE;
}
else
{
// 导致Win32ErrorLogMessage嵌套, 由于module_是NULL不会再次进入这里,
// 所以不会死循环.
DPLOG(WARNING) << "Couldn't open module " << module_
<< " for error message query";
}
}
else
{
hmod = NULL;
}
DWORD len = FormatMessageA(flags, hmod, err_,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
msgbuf, sizeof(msgbuf)/sizeof(msgbuf[0]), NULL);
if(len)
{
while((len>0) && isspace(static_cast<unsigned char>(msgbuf[len-1])))
{
msgbuf[--len] = 0;
}
stream() << ": " << msgbuf;
}
else
{
stream() << ": Error " << GetLastError() << " while retrieving error "
<< err_;
}
}
示例2: acquirePathLock
void acquirePathLock() {
string name = ( boost::filesystem::path( dbpath ) / "mongod.lock" ).string();
#ifdef _WIN32
lockFileHandle = CreateFileA( name.c_str(), GENERIC_READ | GENERIC_WRITE,
0 /* do not allow anyone else access */, NULL,
OPEN_ALWAYS /* success if fh can open */, 0, NULL );
if (lockFileHandle == INVALID_HANDLE_VALUE) {
DWORD code = GetLastError();
char *msg;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&msg, 0, NULL);
string m = msg;
str::stripTrailing(m, "\r\n");
uasserted( 13627 , str::stream() << "Unable to create/open lock file: " << name << ' ' << m << ". Is a mongod instance already running?" );
}
lockFile = _open_osfhandle((intptr_t)lockFileHandle, 0);
#else
lockFile = open( name.c_str(), O_RDWR | O_CREAT , S_IRWXU | S_IRWXG | S_IRWXO );
if( lockFile <= 0 ) {
uasserted( 10309 , str::stream() << "Unable to create/open lock file: " << name << ' ' << errnoWithDescription() << " Is a mongod instance already running?" );
}
if (flock( lockFile, LOCK_EX | LOCK_NB ) != 0) {
close ( lockFile );
lockFile = 0;
uassert( 10310 , "Unable to lock file: " + name + ". Is a mongod instance already running?", 0 );
}
#endif
#ifdef _WIN32
uassert( 13625, "Unable to truncate lock file", _chsize(lockFile, 0) == 0);
writePid( lockFile );
_commit( lockFile );
#else
uassert( 13342, "Unable to truncate lock file", ftruncate(lockFile, 0) == 0);
writePid( lockFile );
fsync( lockFile );
flushMyDirectory(name);
#endif
}
示例3: FormatMessageA
char *err_strA(DWORD dw)
{
static char msgstr[256];
LPVOID lpMsgBuf;
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR) &lpMsgBuf,
0, NULL );
// Display the error message and exit the process
StringCchPrintfA(msgstr, ARRAYSIZE(msgstr), "%d: %s", dw, lpMsgBuf);
return msgstr;
}
示例4: FormatMessageA
const char* COMException::what() const
{
if(!msg)
{
LPSTR readable_hr = nullptr;
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, hr, 0, reinterpret_cast<LPSTR>(&readable_hr), 0, nullptr);
if(readable_hr)
{
msg = FormatMessagef("%1!s! (%2!s!)", readable_hr, function);
LocalFree(readable_hr);
}
else
{
msg = FormatMessagef("HR 0x%1!08x! (%2!s!)", hr, function);
}
}
return msg ? msg : "COMException";
}
示例5: GetErrorMessage
static std::string GetErrorMessage(DWORD error) {
std::string message;
LPVOID buffer = NULL;
DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS;
DWORD lang_id = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
DWORD result = FormatMessageA(flags, NULL, error, lang_id,
reinterpret_cast<LPSTR>(&buffer),
0, NULL);
if (result > 0) {
message.assign(StripNewLine(reinterpret_cast<char*>(buffer)));
}
LocalFree(buffer);
return message;
}
示例6: X_GetLastError
const char* X_GetLastError()
{
#if defined WINDOWS || WIN32
char szBuf[256] = {0};
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpMsgBuf,
0, NULL);
return (const char*)lpMsgBuf;
#else
extern int errno;
errno = 0;
return dlerror();
#endif
}
示例7: DLLEXPORT
DLLEXPORT(char*) hresultString( HRESULT hr )
{
static char msgbuf[256];
int len;
sprintf( msgbuf, "(0x%lx) ", hr );
len = strlen(msgbuf);
FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
msgbuf + len,
256,
NULL
);
return msgbuf;
}
示例8: GetLastErrorMsg
// Generic function to get last error message.
// Call directly after the command or use the error num.
// This function might change the error code.
const char* GetLastErrorMsg()
{
static const size_t buff_size = 255;
#ifdef _WIN32
static __declspec(thread) char err_str[buff_size] = {};
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
err_str, buff_size, nullptr);
#else
static __thread char err_str[buff_size] = {};
// Thread safe (XSI-compliant)
if (strerror_r(errno, err_str, buff_size))
return nullptr;
#endif
return err_str;
}
示例9: win_perror
void win_perror(const char *str)
{
DWORD dwError = GetLastError();
LPVOID lpvMessageBuffer;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpvMessageBuffer, 0, NULL);
//... now display this string
fprintf(stderr, "%s: %s\n", str, lpvMessageBuffer);
// Free the buffer allocated by the system
LocalFree(lpvMessageBuffer);
}
示例10: couchstore_last_os_error
LIBCOUCHSTORE_API
void couchstore_last_os_error(char* buf, size_t size) {
struct _os_error *err = get_os_error_store();
#ifndef WINDOWS
snprintf(buf, size, "errno = %d: `%s'", err->errno_err, strerror(err->errno_err));
#else
char* win_msg = NULL;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err->win_err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &win_msg,
0, NULL);
snprintf(buf, size, "errno = %d: `%s', WINAPI error = %d: `%s'",
err->errno_err, strerror(err->errno_err),
err->win_err, win_msg);
LocalFree(win_msg);
#endif
}
示例11: TestDceErrorInqText
static void TestDceErrorInqText (void)
{
char bufferInvalid [1024];
char buffer [1024]; /* The required size is not documented but would
* appear to be 256.
*/
DWORD dwCount;
dwCount = FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, RPC_S_NOT_RPC_ERROR, 0, bufferInvalid,
sizeof(bufferInvalid)/sizeof(bufferInvalid[0]), NULL);
/* A random sample of DceErrorInqText */
/* 0 is success */
ok ((DceErrorInqTextA (0, (unsigned char*)buffer) == RPC_S_OK),
"DceErrorInqTextA(0...)\n");
/* A real RPC_S error */
ok ((DceErrorInqTextA (RPC_S_INVALID_STRING_UUID, (unsigned char*)buffer) == RPC_S_OK),
"DceErrorInqTextA(valid...)\n");
if (dwCount)
{
/* A message for which FormatMessage should fail
* which should return RPC_S_OK and the
* fixed "not valid" message
*/
ok ((DceErrorInqTextA (35, (unsigned char*)buffer) == RPC_S_OK &&
strcmp (buffer, bufferInvalid) == 0),
"DceErrorInqTextA(unformattable...)\n");
/* One for which FormatMessage should succeed but
* DceErrorInqText should "fail"
* 3814 is generally quite a long message
*/
ok ((DceErrorInqTextA (3814, (unsigned char*)buffer) == RPC_S_OK &&
strcmp (buffer, bufferInvalid) == 0),
"DceErrorInqTextA(deviation...)\n");
}
else
ok (0, "Cannot set up for DceErrorInqText\n");
}
示例12: ErrorCodeToMessage
MEDUSA_NAMESPACE_BEGIN
std::string Exception_System::ErrorCodeToMessage(void)
{
HLOCAL hLocal = nullptr;
if (FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr,
GetLastError(),
0x0,
(LPSTR)&hLocal,
0x0,
nullptr
) == 0x0)
return "Unable to retrieve the exception message";
std::string Res = (LPCSTR)LocalLock(hLocal);
LocalFree(hLocal);
return Res;
}
示例13: GetLastErrorString
std::string GetLastErrorString() {
LPSTR lpBuffer = NULL;
std::string strError;
if(FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR) &lpBuffer,
0,
NULL) != 0) {
strError = lpBuffer;
LocalFree( lpBuffer );
} else {
std::ostringstream buffer; //! Buffer for the log message excluding level, file and line.
buffer << "Unknown error (" << GetLastError() << ").";
strError = buffer.str();
}
return strError;
}
示例14: ipk_perror_win
void ipk_perror_win(unsigned long error)
{
if (error == 0)
return;
char* errmsg = NULL;
unsigned long hr = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
0U, error, LANG_NEUTRAL, (char *)&errmsg, 0U, NULL);
assert(hr > 0);
if (errmsg) {
_ipk_error_log("Chyba #%d: %s", error, errmsg);
}
else {
_ipk_error_log("Chyba #%d", error);
}
LocalFree(errmsg);
}
示例15: set_krberror
static VOID
set_krberror(DWORD errCode, const SEC_CHAR* msg) {
SEC_CHAR* err;
DWORD status;
DWORD flags = (FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS);
status = FormatMessageA(flags,
NULL,
errCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&err,
0,
NULL);
if (status) {
PyErr_Format(KrbError, "SSPI: %s: %s", msg, err);
LocalFree(err);
} else {
PyErr_Format(KrbError, "SSPI: %s", msg);
}
}