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

📄 vmlastsystemerrorcode.cpp

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 CPP
字号:
/*****************************************************************************/
/*                              SOURCE FILE                                  */
/*****************************************************************************/
/*
       $Archive: $

      $Revision: $
          $Date: $
        $Author: $

    Description: Contains the implementation of the VMSysLastError class

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
static char OBJECT_ID[] = "$Revision: $ : $Date: $";
/*****************************************************************************/


#include "../../../stdafx.h"
#include "VMLastSystemErrorCode.h"


/*****************************************************************************/
/*
     FUNCTION NAME:  VMSysLastError::SetLastError

       DESCRIPTION:  stores the OS's last error code and string in this

             INPUT:  void
            OUTPUT:  void

           RETURNS:  void 
*/
void VMSysLastError::SetLastError( void )
{
  m_dwErrorCode = GetLastError();
  FillErrorText();
}
/* end of function "VMSysLastError::SetLastError" */
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  VMSysLastError::FillErrorText

       DESCRIPTION:  propogates m_oErrText based on m_dwErrCode

             INPUT:  void
            OUTPUT:  void

           RETURNS:  void 
*/
void  VMSysLastError::FillErrorText( void )
{
  char   achBuffer[255];
  LPVOID lpMsgBuffer;

  if ( 0 != m_dwErrorCode )
  {        
    FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                    NULL,
                    m_dwErrorCode,
                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                    (LPTSTR) &lpMsgBuffer,
                    0,
                    NULL );
    sprintf( achBuffer, "Error: '%d' reported. ", m_dwErrorCode );
    m_oErrorText = achBuffer;  
    if ( strlen( (const char*)lpMsgBuffer ) )
    {
      char* pchMsgBuffer = (char*)lpMsgBuffer;
      int   iLen = strlen( (const char*)lpMsgBuffer );

      if ( ( '\n' == *( pchMsgBuffer + iLen - 1 ) ) 
        || ( '\r' == *( pchMsgBuffer + iLen - 1 ) ) ) 
      {
        *( pchMsgBuffer + iLen - 1 ) = '\0';
      }

      if ( ( '\n' == *(pchMsgBuffer + iLen - 2 ) ) 
        || ( '\r' == *(pchMsgBuffer + iLen - 2 ) ) ) 
      {
        *( pchMsgBuffer + iLen - 2 ) = '\0';
      }

      m_oErrorText += (const char*)lpMsgBuffer;
    }
    LocalFree( lpMsgBuffer );
  }
}
/* end of function "VMSysLastError::FillErrorText" */
/*****************************************************************************/



/*****************************************************************************/
/* Check-in history */
/*
 *$Log: $
*/
/*****************************************************************************/

⌨️ 快捷键说明

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