Ejemplo n.º 1
0
//++ ------------------------------------------------------------------------------------
// Details:	Retrieve the OS system error message for the given system error code. 
// Type:	Method.
// Args:	vError		- (R) OS error code value.
//			vrwErrorMsg	- (W) The error message.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMIUtilSystemOsx::GetOSErrorMsg( const MIint vError, CMIUtilString & vrwErrorMsg  ) const
{
	// Reset
	vrwErrorMsg.clear();

	bool bOk = MIstatus::failure;
	
	// ToDo: Implement LINUX version
	
	return bOk;
}
//++ ------------------------------------------------------------------------------------
// Details: Retrieve the OS system error message for the given system error code.
// Type:    Method.
// Args:    vError      - (R) OS error code value.
//          vrwErrorMsg - (W) The error message.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool
CMIUtilSystemWindows::GetOSErrorMsg(const MIint vError, CMIUtilString &vrwErrorMsg) const
{
    // Reset
    vrwErrorMsg.clear();

    const MIuint nBufLen = 1024;
    std::unique_ptr<char[]> pBuffer;
    pBuffer.reset(new char[nBufLen]);

    // CMIUtilString Format is not used as cannot replicate the behavior of ::FormatMessage which
    // can take into account locality while retrieving the error message from the system.
    const int nLength = ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, (DWORD)vError,
                                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>(&pBuffer[0]), nBufLen, nullptr);
    bool bOk = MIstatus::success;
    if (nLength != 0)
        vrwErrorMsg = &pBuffer[0];
    else
        bOk = MIstatus::failure;

    return bOk;
}