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所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 关于资源管理器的操作06/24
- ♥ COM组件_403/07
- ♥ STL_stack05/19
- ♥ 一些问题三:编译相关03/22
- ♥ C++标准库_chrono03/28
- ♥ Spdlog记述:二07/09
热评文章
- 关于资源管理器的操作 0
- MFC 自定义消息 0
- 逐行读取txt内容 0
- 非阻塞版本 Sleep实现 0