widestrhelp.h

来自「mpq文件的格式就是一种压缩格式」· C头文件 代码 · 共 77 行

H
77
字号
/*****************************************************************************/
/* UnicodeHelp.h                              Copyright Ladislav Zezula 2001 */
/*---------------------------------------------------------------------------*/
/* Helping file with useful macros for Wide strings support. This module     */
/* must not be used with its source (WideStrHelp.cpp), when no functions from*/
/* the source are used.                                                      */
/*---------------------------------------------------------------------------*/
/*   Date    Ver   Who  Comment                                              */
/* --------  ----  ---  -----------------------------------------------------*/
/* 21.12.01  1.00  Lad  The first version                                    */
/* 09.01.02  1.01  Lad  Added support for BSTR type                          */
/* 06.02.02  1.02  Lad  Added automatic conversion between TCHAR and char    */
/*****************************************************************************/

#ifndef __WIDESTRHELP_H__
#define __WIDESTRHELP_H__

// Macro for getting max. number of characters in a buffer
#define _tsize(buf)  ((sizeof(buf) / sizeof(TCHAR)) - 1)

// Macros for easy converting ANSI to Unicode and back
// Use if you consider the API function too difficult
#ifndef CharToWChar
#define CharToWChar(wstr, str, length) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstr, length/sizeof(WCHAR))
#endif

#ifndef WCharToChar
#define WCharToChar(str, wstr, length) WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wstr, -1, str, length, NULL, NULL)
#endif

//-----------------------------------------------------------------------------
// Automatic conversions when compiling for UNICODE

#ifdef _UNICODE

// Conversion TCHAR --> WCHAR
inline void _tcscpyx(WCHAR * wstr, const TCHAR * str)
{
    wcscpy(wstr, str);           // When Unicode, simply copy the string
}

// Conversion char --> TCHAR
inline void _tcscpyx(TCHAR * tstr, const char * str)
{
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, tstr, strlen(str)+1);
}

#endif

//-----------------------------------------------------------------------------
// Automatic conversions when compiling for ANSI

#ifndef _UNICODE

// ANSI : Conversion TCHAR --> WCHAR
inline void _tcscpyx(WCHAR * wstr, const TCHAR * str)
{
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstr, strlen(str)+1);
}

// Conversion char --> TCHAR
inline void _tcscpyx(TCHAR * tstr, const char * str)
{
    strcpy(tstr, str);
}

#endif

//-----------------------------------------------------------------------------
// Public functions

// BSTR helping functions
TCHAR * BSTRToTCHAR(BSTR bsSrc);        // Free the result using 'delete'
BSTR    TCHARToBSTR(TCHAR * szText);    // Free the result using SysFreeString

#endif  // __WIDESTRHELP_H__

⌨️ 快捷键说明

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