头文件包含
#include <string>
#include <codecvt>
函数定义
std::wstring Utils_string_to_wstring(std::string origin_data)
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring wide = converter.from_bytes(origin_data);
return wide;
}
std::string Utils_GetModuleFilePath()
{
TCHAR buf[MAX_PATH] = { 0 };
GetModuleFileName(NULL, buf, MAX_PATH);
#ifdef UNICODE
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
std::string strPath = conv.to_bytes(buf);
#else
std::string strPath = buf;
#endif
strPath = strPath.substr(0, strPath.rfind(\) + 1);
return strPath;
}
调用函数
std::string service_path = Utils_GetModuleFilePath();
std::wstring wstr_service_path = Utils_string_to_wstring(service_path);