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

📄 yb_base.h

📁 网吧电量采集、温湿度采集串口通信实例程序
💻 H
📖 第 1 页 / 共 4 页
字号:

private:
  unsigned __int32 CRC;
  unsigned __int32 _InitValue;

  static bool TB_Initialized;
  static unsigned __int32 TB[256];
  inline unsigned __int32 *fGetTable(void) { return TB; }
};
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
class PACKAGE TCRC16 //CCITT 校验码直接使用
{
public:
  TCRC16(unsigned __int16 InitValue=0);

  inline operator unsigned __int16 () { return CRC; }
  inline TCRC16 & operator << (unsigned __int8 c) { CRC = TB[((CRC>>8)^c) & 0xff] ^ (CRC<<8); return *this; }
  __property unsigned __int16 Value = { read = CRC };
  unsigned __int16 Check(void *p, unsigned long n);
  inline void Reset(void) { CRC = _InitValue; }
  inline void Reset(unsigned __int16 InitValue) { CRC = _InitValue = InitValue; }
  __property const unsigned __int16 * Table = { read = fGetTable };

private:
  unsigned __int16 CRC;
  unsigned __int16 _InitValue;

  static bool TB_Initialized;
  static unsigned __int16 TB[256];
  inline unsigned __int16 *fGetTable(void) { return TB; }
};
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
class PACKAGE TCRC8 //SMART-CARD
{
public:
  TCRC8(unsigned __int8 InitValue=0);

  inline operator unsigned __int8 () { return CRC; }
  inline TCRC8 & operator << (unsigned __int8 c) { CRC = TB[CRC^c]; return *this; }
  __property unsigned __int8 Value = { read = CRC };
  unsigned __int8 Check(void *p, unsigned long n);
  inline void Reset(void) { CRC = _InitValue; }
  inline void Reset(unsigned __int8 InitValue) { CRC = _InitValue = InitValue; }
  __property const unsigned __int8 * Table = { read = fGetTable };

private:
  unsigned __int8 CRC;
  unsigned __int8 _InitValue;

  static bool TB_Initialized;
  static unsigned __int8 TB[256];
  inline unsigned __int8 *fGetTable(void) { return TB; }
};
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
class PACKAGE TBASE64
{
public:
  int Encode(void *lpDest, const void *lpSour, int nBytes);
  int Decode(void *lpDest, const void *lpSour, int nBytes);
  TBASE64(const char *lpTab65=0); //65 bytes table, the last one is the terminator of Base64
private:
  char _Base64Tbl[65];
  static const char DefBase64Tbl[65];
};
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
class PACKAGE TSysInfo
{
public:
  typedef struct
   {
     DWORD OSID;           //VER_PLATFORM_WIN32s, VER_PLATFORM_WIN32_WINDOWS, VER_PLATFORM_WIN32_NT
     char  OSName[256];    //"Windows 98", "Windows ME", "Windows NT", "Windows 2000", "Windows XP" ...
     DWORD MajorVer;       //4    //4.10.1998
     DWORD MinorVer;       //10   //4.10.1998
     DWORD BuildNum;       //1998 //4.10.1998
     TCHAR OtherInfo[256]; //"Service Pack 1"
     char  RegUser[256];   //Registered User
     char  RegOrg[256];    //Registered Organization
   } OS_INFO;

public:
   TSysInfo();
   __property OS_INFO *OS = { read = fGetOS };

private:
   void fGetOsInfo(void);
   OS_INFO OsInfo;
   bool bOsInfo;

private:
   inline OS_INFO *fGetOS(void)
    {
      if(!bOsInfo)
        fGetOsInfo();
      return &OsInfo;
    }
};
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
class PACKAGE TLocalNetInfo
{
public:
   __property bool               Valid     = { read = _bWinSockOK };
   __property TVictorString      HostName  = { read = _HostName   };
   __property TVictorStringList *Addresses = { read = _All_IPs    };

   TLocalNetInfo();
   virtual ~TLocalNetInfo();

protected:
   bool _bWinSockOK;
   TVictorString _HostName;
   TVictorStringList *_All_IPs;
   virtual void _GetLocalHostInfo(void);
};
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
class PACKAGE TFileMapping
{
public:
  typedef union
   {
     unsigned __int64 Size;
     struct
      {
        unsigned __int32 SizeLo;
        unsigned __int32 SizeHi;
      };
   } MAPSIZE;

  TFileMapping(const char *lpszMapName, unsigned __int64 iMapSize, DWORD flProtect=PAGE_READWRITE);
  ~TFileMapping();

  bool Open(void);
  void Close(void);

  operator HANDLE() { return _hMap; }

  __property bool   Opened    = { read = fOpened      };
  __property bool   Exists    = { read = fGetExists   };
  __property HANDLE Handle    = { read = _hMap        };
  __property DWORD  OpenError = { read = _dwOpenError };
  __property unsigned __int64 Size = { read = _MapSize.Size };

protected:
  bool fOpened(void) { return _hMap!=NULL; }
  bool fGetExists(void) { return _dwOpenError==ERROR_ALREADY_EXISTS; }

  HANDLE _hMap;
  char *_MapName;
  DWORD _flProtect;
  MAPSIZE _MapSize;
  DWORD _dwOpenError;
};
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
class PACKAGE TMapView
{
public:
  typedef union
   {
     unsigned __int64 Offs;
     struct
      {
        unsigned __int32 OffsLo;
        unsigned __int32 OffsHi;
      };
   } MAPOFFS;

  TMapView(HANDLE hMap, unsigned __int64 iOffset=0, DWORD dwSize=0, DWORD dwAccess=FILE_MAP_WRITE);
  ~TMapView();

  bool Open(void);
  void Close(void);

  __property bool Opened  = { read = fOpened   };
  __property void *Buffer = { read = _lpBuffer };
  __property DWORD Size   = { read = _dwSize   };

protected:
  bool fOpened(void) { return _lpBuffer!=NULL; }

  HANDLE  _hMap;
  MAPOFFS _Offset;
  DWORD   _dwSize, _dwAccess;
  LPVOID  _lpBuffer;
};
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
class PACKAGE TSharedMemory
{
public:
  TSharedMemory(const char *lpszMapName, unsigned int iMemSize, DWORD flProtect=PAGE_READWRITE);
  virtual ~TSharedMemory();

  typedef struct
   {
     HWND hMainWnd;
     HWND hMainForm;
     char Data[1];
   } TAppInfo;

  __property bool Valid = { read=fGetValid };
  __property bool Exists = { read=_bExists };
  __property void *Buffer = { read=lpBuffer };
  __property DWORD Size = { read=fGetSize };
  __property TAppInfo *AppInfo = { read=fGetAppInfo };

  bool ActiveAppWnd(void);
  void ClearBuffer(void);

  static BOOL SetForegroundWindow(HWND hWnd);

private:
  TFileMapping *lpMapping;
  TMapView     *lpView;
  void         *lpBuffer;
  bool         _bExists;
  unsigned int _iMemSize;

  inline DWORD fGetSize(void) { return _iMemSize; }
  inline bool fGetValid(void) { return lpBuffer!=NULL; }
  inline TAppInfo *fGetAppInfo(void) { return (TAppInfo*)lpBuffer; }
};
//---------------------------------------------------------------------------
extern int PACKAGE _vcs_wcscmp(const wchar_t *a, const wchar_t *b, TVictorChineseSortType t); //字串比較
extern int PACKAGE _vcs_wcsicmp(const wchar_t *a, const wchar_t *b, TVictorChineseSortType t); //字串比較
//---------------------------------------------------------------------------
extern int PACKAGE _vcs_is_charchinese(const wchar_t c); //檢查一個字元是否為漢字
extern int PACKAGE _vcs_get_strokecount(const wchar_t c); //獲取一個漢字的筆劃數,不是漢字返回零
//---------------------------------------------------------------------------
extern TVictorWideString PACKAGE _vcs_get_bopomofo(wchar_t c); //獲取漢字的註音 (ㄅㄆㄇㄈ),不是漢字返回空
extern TVictorWideString PACKAGE _vcs_get_pinyin(wchar_t c); //獲取漢字的拼音 (abcd),不是漢字返回空
//---------------------------------------------------------------------------
extern TVictorWideString PACKAGE _vcs_get_bopomofo(TVictorWideString ws); //獲取漢字的註音 (ㄅㄆㄇㄈ),不是漢字返回空
extern TVictorWideString PACKAGE _vcs_get_pinyin(TVictorWideString ws); //獲取漢字的拼音 (abcd),不是漢字返回空
//---------------------------------------------------------------------------
} using namespace TVictorFuncs;
//---------------------------------------------------------------------------
//////////////// 字符串、文件、文件名、目录 (文件夹) 的函数 /////////////////
//---------------------------------------------------------------------------
namespace TBinFileFuncs {
//---------------------------------------------------------------------------
extern TVictorString PACKAGE ToBackSlashes(TVictorString s); //把带有 "/" 的路径转化为 "\\"
extern TVictorString PACKAGE ToUnixSlashes(TVictorString s); //把带有 "\\" 的路径转化为 "/"
extern TVictorString PACKAGE AddBackSlash(TVictorString s); //把没有 "\\" 结束的路径加上结束 "\\"

extern TVictorString PACKAGE GetPathFromFullName(TVictorString s);   //从完整路径文件名提取路径: "D:\\PATH\\"
extern TVictorString PACKAGE GetFullNameWithoutExt(TVictorString s); //从完整路径文件名提取含路径的文件名,不带扩展名: "D:\\PATH\\FILENAME"
extern TVictorString PACKAGE GetExtName(TVictorString s);            //从完整的路径文件名提取扩展名: "EXT" 不包括'.'
extern TVictorString PACKAGE GetFileName(TVictorString s);           //从完整的路径文件名提取不含路径的文件名.扩展名: "FILENAME.EXT"

extern int  PACKAGE MkDir(TVictorString Path);        //创建子目录 (文件夹), 有无结束 "\\" 都可以
extern int  PACKAGE RmDir(TVictorString Path);        //删除子目录 (文件夹), 有无结束 "\\" 都可以
extern int  PACKAGE MakeFullPath(TVictorString Path); //创建完整的子目录 (文件夹), 需要有结束 "\\", 程序可以直接带文件名参数,根据文件名的路径创建目录
extern bool PACKAGE ExistPath(TVictorString Path);    //判断子目录 (文件夹) 是否存在, 有无结束 "\\" 都可以
extern bool PACKAGE ExistFile(TVictorString Name, long *lpAttrib=0);    //判断文件是否存在

extern int PACKAGE f_copy(TVictorString dest, TVictorString sour); //复制文件
extern int PACKAGE MakePercent(unsigned long lPos, unsigned long lCount); //return lPos/lCount*100

extern bool PACKAGE WriteLogFileInfo(TVictorString FileName, const char *lpInfo, ...);
extern TVictorString PACKAGE GetShErrInfo(int ErrNo); //ShellExecute()函数的返回值->错误信息

extern void PACKAGE ShutDownWindows(unsigned int iOpt); //EWX_POWEROFF, EWX_REBOOT, EWX_LOGOFF, EWX_FORCE, EWX_SHUTDOWN

//-------------------- Cyclic Redundancy Check (CRC) ------------------------
extern void PACKAGE _Crc8(unsigned char &c, unsigned char x);        // \  ..............
extern void PACKAGE _Crc16(unsigned short &c, unsigned char x);      //  \ 初始值为 0
extern void PACKAGE _Crc32(unsigned long &c, unsigned char x);       //  / 校验码直接使用
extern void PACKAGE _CrcCcitt16(unsigned short &c, unsigned char x); // /  ~~~~~~~~~~~~~~
extern void PACKAGE _CrcCcitt32(unsigned long &c, unsigned char x);  // -- 初始值为 FFFFFFFF 校验码取反使用

extern void PACKAGE _Crc8(unsigned char &c, void *s, int n);        // \  ..............
extern void PACKAGE _Crc16(unsigned short &c, void *s, int n);      //  \ 初始值为 0
extern void PACKAGE _Crc32(unsigned long &c, void *s, int n);       //  / 校验码直接使用
extern void PACKAGE _CrcCcitt16(unsigned short &c, void *s, int n); // /  ~~~~~~~~~~~~~~
extern void PACKAGE _CrcCcitt32(unsigned long &c, void *s, int n);  // -- 初始值为 FFFFFFFF 校验码取反使用
//---------------------------------------------------------------------------
} //TBinFileFuncs
//---------------------------------------------------------------------------
////////////////////////////// Global Variables /////////////////////////////
//---------------------------------------------------------------------------
namespace TVictorFuncs {
//---------------------------------------------------------------------------
extern PACKAGE TAppLang AppLang;
extern PACKAGE TStringLocale _SysLocale;
//---------------------------------------------------------------------------
} using namespace TVictorFuncs;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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