⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rcerrormessage.cpp

📁 MSSQL备份及恢复的VC++源代码。提供给大家学习。
💻 CPP
字号:
//																			//
//			Created by Ozzy Osbourne(maojun) . HangZhou . 20030214			//
//																			//
//////////////////////////////////////////////////////////////////////////////

// CRcErrorMessage is format run time error message. 
// 
// Expect bugs.
// 
// Please use and enjoy. Please let me know of any bugs/mods/improvements 
// that you have found/implemented and I will fix/incorporate them into this file.
// Please send report to OzzyJMalmsteen@yahoo.com.cn or Ozzman@163.net

#include "stdafx.h"
#include "RcMSSQL.h"
#include "RcErrorMessage.h"

// Stardard headers
#include <lmerr.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRcErrorMessage::CRcErrorMessage()
{
	m_strErrorMessage = _T("");
}

CRcErrorMessage::~CRcErrorMessage()
{

}

BOOL CRcErrorMessage::FormatErrorMessage(LPCTSTR lpszStep, DWORD dwLastError)
{
	// Format message flags.
    DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
						FORMAT_MESSAGE_IGNORE_INSERTS |
						FORMAT_MESSAGE_FROM_SYSTEM ;

 	// Default to system source.
    HMODULE hModule = NULL;
	// If dwLastError is in the network range, load the message source.
    if (dwLastError >= NERR_BASE && dwLastError <= MAX_NERR)
	{
        hModule = LoadLibraryEx (TEXT("netmsg.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE);

        if (hModule != NULL)
		{
            dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE;
		}
    }

    DWORD dwMessageSize;
    LPSTR MessageBuffer;
    // Call FormatMessage() to allow for message text to be acquired from the system or from the supplied module handle.
    if (dwMessageSize = FormatMessage (
        dwFormatFlags,
        hModule, // Module to get message from (NULL == system)
        dwLastError,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language.
        (LPSTR) &MessageBuffer,
        0,
        NULL
        ))
    {

		// Output message string on stderr.
//		DWORD dwBytesWritten;
//		WriteFile(GetStdHandle(STD_ERROR_HANDLE), MessageBuffer, dwMessageSize, &dwBytesWritten, NULL);
		m_strErrorMessage.Format ("%s: %s", lpszStep, MessageBuffer);

		// Free the buffer allocated by the system.
		LocalFree (MessageBuffer);
    }
	else
	{
		m_strErrorMessage.Format ("%s: %u", lpszStep, dwLastError);

//		ExitProcess(dwLastError);
		return FALSE;
	}

    // If we loaded a message source, unload it.
    if (hModule != NULL)
	{
        FreeLibrary (hModule);
	}

//	ExitProcess(dwLastError);
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -