當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。