当前位置: 首页>>代码示例>>C++>>正文


C++ FormatMessageA函数代码示例

本文整理汇总了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_;
     }
 }
开发者ID:hgl888,项目名称:x-framework,代码行数:42,代码来源:logging.cpp

示例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
    }
开发者ID:nvdnkpr,项目名称:mongo,代码行数:42,代码来源:instance.cpp

示例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;
}
开发者ID:CarterTsai,项目名称:hime,代码行数:20,代码来源:util.cpp

示例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";
 }
开发者ID:corsix,项目名称:nice,代码行数:20,代码来源:com.cpp

示例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;
}
开发者ID:Zeex,项目名称:samp-plugin-profiler,代码行数:20,代码来源:system_error_win32.cpp

示例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
}
开发者ID:Fantasticer,项目名称:XAPI2,代码行数:20,代码来源:XApiC.cpp

示例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;
}
开发者ID:jjinkou2,项目名称:ComForGHC7.4,代码行数:20,代码来源:ComPrimSrc.c

示例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;
}
开发者ID:Ahriman,项目名称:dolphin,代码行数:23,代码来源:Misc.cpp

示例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);

}
开发者ID:tidatida,项目名称:c10mbench,代码行数:20,代码来源:pixie-mem.c

示例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
}
开发者ID:apage43,项目名称:couchstore,代码行数:20,代码来源:couch_db.c

示例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");
}
开发者ID:Barrell,项目名称:wine,代码行数:41,代码来源:rpc.c

示例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;
}
开发者ID:GrimDerp,项目名称:medusa,代码行数:21,代码来源:exception.cpp

示例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;
}
开发者ID:DaveMachine,项目名称:ArxLibertatis,代码行数:21,代码来源:FilesystemWindows.cpp

示例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);
}
开发者ID:zcsevcik,项目名称:edu,代码行数:21,代码来源:log.c

示例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);
    }
}
开发者ID:schlenk,项目名称:winkerberos,代码行数:21,代码来源:kerberos_sspi.c


注:本文中的FormatMessageA函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。