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

📄 vmwatcheroutput.h

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 H
字号:
#ifndef VM_OBSERVER_H_INCLUDED
#define VM_OBSERVER_H_INCLUDED
/*****************************************************************************/
/*                              HEADER FILE                                  */
/*****************************************************************************/
/*
       $Archive: $

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

    Description: Declaration of the functions and helper id's for the debug
                 messages

                      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.
*/
/*****************************************************************************/

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

extern bool g_bVMTraceEnabled;

static  LPCSTR  g_DiagnosticOut          = _T( "SCXP API Tracer" );
static  LPCSTR  g_DiagnosticOutClassName = _T( "SCXP API Tracer Window" );



/*****************************************************************************/
/*
     FUNCTION NAME:  DebugOutASCII

       DESCRIPTION:  sends a diagnostic message to the diagnostic window

             INPUT:  p - the message text
            OUTPUT:  none

           RETURNS:  void 
*/
inline void DebugOutASCII( LPCSTR p )
{
   COPYDATASTRUCT cd; 
   HWND hWnd = ::FindWindow( g_DiagnosticOutClassName, g_DiagnosticOut ); 
   if ( hWnd )
   {  
      cd.dwData = 0;
      cd.cbData = ( strlen( p ) + 1 ) * sizeof( char );
      cd.lpData = ( void* )p; 
      ::SendMessage( hWnd, WM_COPYDATA, 0, (LPARAM)&cd );  
   } 
}

#define DEBUGOUT_ASCII(p) DebugOutASCII( p );

/* End of function "DebugOutASCII"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  DebugOutWideChar

       DESCRIPTION:  sends a wide-char diagnostic message to the diagnostic
                     window

             INPUT:  p - the text for the message
            OUTPUT:  none

           RETURNS:  void 
*/
inline void DebugOutWideChar( LPCWSTR p )
{
   COPYDATASTRUCT cd; 
   HWND hWnd = ::FindWindow( g_DiagnosticOutClassName, g_DiagnosticOut ); 
   if ( hWnd )
   {  
      cd.dwData = 0xFEFF;
      cd.cbData = ( wcslen( p ) + 1 ) * sizeof( wchar_t );
      cd.lpData = ( void* )p; 
      ::SendMessage( hWnd, WM_COPYDATA, 0, (LPARAM)&cd );  
   } 
}

#define DEBUGOUT_WIDECHAR( p ) DebugOutWideChar( p );

/* End of function "DebugOutWideChar"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  DebugOut

       DESCRIPTION:  formats a message for the diagnostic window

             INPUT:  pFormat - the format string
                     ... - the arguments
            OUTPUT:  

           RETURNS:  void  
*/
inline void DebugOut( LPCTSTR pFormat, ... )
{
  if ( g_bVMTraceEnabled )
  {
    va_list args;
    va_start( args, pFormat );

    _TCHAR buffer[ 1024 * sizeof( _TCHAR ) ];
    wvsprintf( buffer, pFormat, args );

    #ifdef UNICODE
    DebugOutWideChar( buffer );
    #else
    DebugOutASCII( buffer );
    #endif

    va_end( args );
  }
}

#define DEBUGOUT ::DebugOut

/* End of function "DebugOut"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  DebugOutLastError

       DESCRIPTION:  creates a diagnostic message based on last error

             INPUT:  pFormat - the format string
                     ... - the arguments
            OUTPUT:  

           RETURNS:  0 or the last error 
*/
inline DWORD DebugOutLastError( LPCTSTR pFormat, ... )
{
   if ( ::GetLastError() == 0 ) 
      return 0;
   
   va_list args;
   va_start( args, pFormat );

   _TCHAR buffer[ 1024 * sizeof( _TCHAR ) ];
   wvsprintf( buffer, pFormat, args );

   LPVOID pMessage;
   DWORD  result;
   result = ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                             NULL,
                             GetLastError(),
                             MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ),
                             (LPTSTR)&pMessage,
                             0,
                             NULL );
  
   lstrcat( buffer, _T(" : ") );
   lstrcat( buffer, (TCHAR*)pMessage );
   DEBUGOUT( buffer );
    
   if ( result )
      ::LocalFree( pMessage );
   
   va_end( args );
   return result;
}

#define DEBUGOUT_LASTERROR ::DebugOutLastError

/* End of function "DebugOutLastError"
/*****************************************************************************/



#endif


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


⌨️ 快捷键说明

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