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
- ♥ 逐行读取txt内容10/12
- ♥ Windows下创建局域网FTP服务器10/27
- ♥ 2020_04_2204/23
- ♥ C++并发编程 _ 内存模型原子操作08/07
- ♥ 大话数据结构_算法相关&&AVL&&B树相关02/20
热评文章
- 关于资源管理器的操作 0
- MFC 自定义消息 0
- 逐行读取txt内容 0
- 非阻塞版本 Sleep实现 0