📄 widestrhelp.h
字号:
/*****************************************************************************/
/* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -