📄 convert.h
字号:
/*
Copyright (c) 1999, Elixir Studio
Author: Konstantin Bukreev
E-mail: konstantin@mail.primorye.ru
Created: 18.08.99 16:06:48
Version: 1.0.1
Description: converts and copies wchar_t string to char string and back
*/
#ifndef _convert_e4b9ff2d_556c_11d3_9283_0080adb811c5
#define _convert_e4b9ff2d_556c_11d3_9283_0080adb811c5
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
namespace _ex_util
{
struct _convert
{
template <class _Ch> static HRESULT make (const _Ch* out, const char* in, int size_out);
template <class _Ch> static HRESULT make (const _Ch* to, const wchar_t* from, int size_out);
//Instantiation
template<> static HRESULT make (const char* out, const char* in, int size_out)
{
__try{ memcpy((void*)out, (void*)in, min(size_out, lstrlenA(in)));}
__except(1) {return E_UNEXPECTED;}
return S_OK;
}
template<> static HRESULT make (const wchar_t* out, const wchar_t* in, int size_out)
{
__try {memcpy((void*)out, (void*)in, min((size_out * sizeof wchar_t), (lstrlenW(in) * sizeof wchar_t)));}
__except(1) {return E_UNEXPECTED;}
return S_OK;
}
template<> static HRESULT make (const wchar_t* out, const char* in, int size_out)
{
int res = 0;
__try { res = MultiByteToWideChar(CP_ACP, 0, in, lstrlenA(in), (wchar_t*)out, size_out);}
__except(1) {return E_UNEXPECTED;}
return res != 0 ? S_OK : E_FAIL;
}
template<> static HRESULT make (const char* out, const wchar_t* in, int size_out)
{
int res = 0;
__try {res = WideCharToMultiByte(CP_ACP, 0, in, lstrlenW(in), (char*)out, size_out, 0, 0);}
__except(1) {return E_UNEXPECTED;}
return res != 0 ? S_OK : E_FAIL;
}
static int _strlen (wchar_t* str) {return lstrlenW(str);}
static int _strlen (char* str) {return lstrlenA(str);}
};
}
#endif //_convert_e4b9ff2d_556c_11d3_9283_0080adb811c5
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -