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

📄 utility.h

📁 VC++串口通信设。本书详细说明讲解了在VC++环境下编写串口通信得过程。值得一看
💻 H
字号:
#ifndef UTILITY_H
#define UTILITY_H

// Get needed include files
#include <iostream>
#include <string>
#include "StdInc.h"


// Color constants
#ifdef USE_MFC
   const COLORREF Black   = RGB(0,   0,   0);
   const COLORREF White   = RGB(255, 255, 255);
   const COLORREF Red     = RGB(255, 0,   0);
   const COLORREF Green   = RGB(0,   255, 0);
   const COLORREF Blue    = RGB(0,   0,   255);
   const COLORREF Yellow  = RGB(255, 255, 0);
   const COLORREF Magenta = RGB(255, 0,   255);
   const COLORREF Cyan    = RGB(0,   255, 255);
#endif


//
// Determine the utility module's native string type
//
#ifdef USE_MFC
   #define UTILSTR    CString
#else
   #define UTILSTR    std::string
#endif


//
// If the preprocessor symbol QUE_VERBOSE is not defined, all calls to 
// VerboseMsg() will be no-ops. Otherwise the VerboseMsg() calls will be
// directed to cout or MFC's TRACE() facility, depending on whether or not
// MFC is being used.
//
#ifdef QUE_VERBOSE

   // Enable display of informational fluff
   inline void VerboseMsg(const UTILSTR &strMsg)
   {
      #ifdef USE_MFC
         TRACE0(strMsg);
      #else
         #ifdef USE_ATL
         #else
            std::cout << "VERBOSE: " << strMsg;
         #endif
      #endif
   }

#else

   // No messages, please
   inline void VerboseMsg(const UTILSTR &) { }

#endif


// Generic error reporting function
// Display an error text and HRESULT
void ReportError(const std::string& strErrorText, HRESULT hResult);


// Convert a ULONG to a string or CString object
UTILSTR ULongToStr(const ULONG ulNumber);


// Unicode/ANSI string conversion routines
HRESULT __fastcall AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW);
HRESULT __fastcall UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA);


// Macro to help with coding of nested class' IUnknown methods
#ifdef USE_MFC

#define IMPLEMENT_NESTED_IUNKNOWN(outerclass, innerclass)    \
                                                             \
      STDMETHODIMP_(ULONG)                                   \
      outerclass::X##innerclass::AddRef()                    \
      {                                                      \
         METHOD_PROLOGUE(outerclass, innerclass)             \
         return pThis->ExternalAddRef();                     \
      }                                                      \
                                                             \
      STDMETHODIMP_(ULONG)                                   \
      outerclass::X##innerclass::Release()                   \
      {                                                      \
         METHOD_PROLOGUE(outerclass, innerclass)             \
         return pThis->ExternalRelease();                    \
      }                                                      \
                                                             \
      STDMETHODIMP                                           \
      outerclass::X##innerclass::QueryInterface(REFIID riid, \
                                                PPVOID ppv)  \
      {                                                      \
         METHOD_PROLOGUE(outerclass, innerclass)             \
         return pThis->ExternalQueryInterface(&riid, ppv);   \
      }

#endif


// THE math constant
const DOUBLE pi = 3.1415926535;

// Convenient math stuff
inline DOUBLE Radians(USHORT usDegrees)
{
   return ((DOUBLE) usDegrees) / (360.0 / (2.0 * pi));
}


// Function to seed the random number generator based on the system time
void SeedRandomGenerator();

#endif

⌨️ 快捷键说明

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