mercredi 4 septembre 2019

deprecated_string_conv_gen: conversion from a string literal to pointer-to-character (non-const) is deprecated in C++

From the coverity tool, I am getting the below warning message in the C++ code:

deprecated_string_conv_gen: conversion from a string literal to pointer-to-character (non-const) is deprecated

at the below line:

si.lpDesktop = L"winsta0\default";

Could anyone please help me how to resolve this warning message?

Below is the complete code snippet:

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;
}

Declaration:

LPWSTR  lpDesktop;

Aucun commentaire:

Enregistrer un commentaire