// 将单字节转化成宽字节的字符串
std::wstring s2ws(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;
}
//创建深层次的路径
BOOL CreateDeepDirectory(const char * lpPathName, //directory name
LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
)
{
string strPath = "";
char pszSrc[MAX_PATH] = { 0 };
strcpy(pszSrc, lpPathName);
char *ptoken = strtok(pszSrc, "\\");
while (ptoken)
{
strPath += ptoken;
strPath += "\\";
if (!access(strPath.c_str(), 0) == 0)
{ //创建失败时还应删除已创建的上层目录,此次略
wstring str = s2ws(strPath);
if (!CreateDirectory(str.c_str(), lpSecurityAttributes))
{
return FALSE;
}
}
ptoken = strtok(NULL, "\\");
}
return TRUE;
}
std::wstring s2ws(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;
}
//创建深层次的路径
BOOL CreateDeepDirectory(const char * lpPathName, //directory name
LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
)
{
string strPath = "";
char pszSrc[MAX_PATH] = { 0 };
strcpy(pszSrc, lpPathName);
char *ptoken = strtok(pszSrc, "\\");
while (ptoken)
{
strPath += ptoken;
strPath += "\\";
if (!access(strPath.c_str(), 0) == 0)
{ //创建失败时还应删除已创建的上层目录,此次略
wstring str = s2ws(strPath);
if (!CreateDirectory(str.c_str(), lpSecurityAttributes))
{
return FALSE;
}
}
ptoken = strtok(NULL, "\\");
}
return TRUE;
}
11万+

被折叠的 条评论
为什么被折叠?



