string→LPCSTR
1 2 3 4 5 6 7 8 9 10 |
LPCWSTR stringToLPCWSTR(std::string orig) { size_t origsize = orig.length() + 1; const size_t newsize = 100; size_t convertedChars = 0; wchar_t *wcstring = (wchar_t *)malloc(sizeof(wchar_t)*(orig.length() - 1)); mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE); return wcstring; } |
LPCSTR→string
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
BOOL WCharToMByte(LPCWSTR lpcwszStr, string &str) { DWORD dwMinSize = 0; LPSTR lpszStr = NULL; dwMinSize = WideCharToMultiByte(CP_OEMCP, NULL, lpcwszStr, -1, NULL, 0, NULL, FALSE); if (0 == dwMinSize) { return FALSE; } lpszStr = new char[dwMinSize]; WideCharToMultiByte(CP_OEMCP, NULL, lpcwszStr, -1, lpszStr, dwMinSize, NULL, FALSE); str = lpszStr; delete[] lpszStr; return TRUE; } |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ COM组件_403/07
- ♥ Windows 核心编程 _ 内核对象一06/04
- ♥ Lua_基础 类型&&值09/26
- ♥ Mathjax在博客中问题记录06/01
- ♥ 行为型:中介者模式09/13
- ♥ 大话数据结构_赫夫曼树与应用01/11