【发布时间】:2019-09-04 16:43:35
【问题描述】:
通过覆盖工具,我在 C++ 代码中收到以下警告消息:
deprecated_string_conv_gen:不推荐从字符串文字到指针到字符(非常量)的转换
在下面一行:
si.lpDesktop = L"winsta0\default";
谁能帮我解决这个警告信息?
下面是完整的sn-p代码:
LONG RcRegJob::CreateProcessandExit()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
WCHAR pwszMcSvrCntPath[MAX_PATH];
DWORD dwExitCode = 0;
dwExitCode = ::GetModuleFileName(NULL, pwszMcSvrCntPath, MAX_PATH);
if (dwExitCode)
{
std::wstring strFilePath = pwszMcSvrCntPath;
std::wstring strProcessName;
int npos = strFilePath.rfind(L"\\");
strProcessName = strFilePath.substr(npos + 1, strFilePath.length());
strFilePath = strFilePath.substr(0, npos);
::ZeroMemory(&si, sizeof(si));
::ZeroMemory(&pi, sizeof(pi));
si.cb = sizeof(si);
si.lpDesktop = L"winsta0\\default";
{
dwExitCode = ::CreateProcess(0, (LPWSTR)strProcessName.c_str(),
0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0,
strFilePavth, &si, &pi);
}
if (0 == dwExitCode)
{
dwExitCode = ::GetLastError();
}
else
{
exit(0);
}
}
return dwExitCode;
}
声明:
LPWSTR lpDesktop;
【问题讨论】: