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所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ MFC 自定义消息04/29
- ♥ 红黑树05/01
- ♥ Lua_调用 C++函数:传递表&&参数类型检测10/06
- ♥ glog记述:概述使用06/30
- ♥ Go 基础:第二篇04/18
- ♥ C标准库_cctype12/15
热评文章
- 关于资源管理器的操作 0
- MFC 自定义消息 0
- 逐行读取txt内容 0
- 非阻塞版本 Sleep实现 0