MFC中 将std::string转换为LPCTSTR的方法
在MFC中将std::string转换为LPCTSTR的方法,在网上找了好久,终于被我发现了。
http://blog.sina.com.cn/s/blog_6f7e64f801014sjo.html
需要自己写一个转换函数:
std::wstring StoWs(const std::string& s)
{
 int len;
 int slength = (int)s.length() + 1;
 len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); 
 wchar_t* buf = new wchar_t[len];
 MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
 std::wstring r(buf);
 delete[] buf;
 return r;
}
std::string s;
如果是 UNICODE 字符的话:
std::wstring stemp = StoWs(s); 
LPCWSTR result = stemp.c_str();
如果不是:
LPCWSTR result = s.c_str();
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号