Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winapi 关于ShellExecute函数的几个问题_Winapi_Mfc_Shellexecute - Fatal编程技术网

Winapi 关于ShellExecute函数的几个问题

Winapi 关于ShellExecute函数的几个问题,winapi,mfc,shellexecute,Winapi,Mfc,Shellexecute,我想调用如下命令: std::string szArg = "-i " + m_strSign; ShellExecuteA(NULL, "open", strToolupdater.c_str(), szArg.c_str(), NULL, SW_NORMAL); std::cout << strToolupdater << " " << szArg << std::endl; 我正在使用以下代码: std::string szArg = "

我想调用如下命令:

std::string szArg = "-i " + m_strSign;
ShellExecuteA(NULL, "open", strToolupdater.c_str(), szArg.c_str(), NULL, SW_NORMAL);
std::cout << strToolupdater << " " << szArg << std::endl;
我正在使用以下代码:

 std::string szArg = " -i " + m_strSign;
 wstringstream wss;
 wss<<szArg.c_str();
 wstringstream wssa;
 wssa<<strToolupdater.c_str();
 ShellExecute(NULL,TEXT("open"), wssa.str().c_str(), wss.str().c_str(),TEXT(""),SW_NORMAL);
 wcout<<wssa.str().c_str()<<wss.str().c_str()<<endl;

预期结果是执行ToolUpdater.exe-i Hackeroid_Qqhcs,但实际结果是执行ToolUpdater.exe,输入参数无效。

问题是您将std::string和std::wstring数据混合在一起,并且这样做不正确


std::wstringstream没有运算符,预期结果是什么?顺便说一句,不要发布代码的图片,而是发布代码。预期结果是ToolUpdater.exe-i Hackeroid_Qqhcs,实际结果是ToolUpdater.exe。参数无效。请更新您的问题,因为此处的问题完全不清楚。请阅读以下内容:。您的代码有几个问题。最重要的一点是,对您的呼叫没有错误处理。此API报告的与参数相似的错误代码均无效。你从哪儿弄来的?这并不是说,您的参数没有错。他们是。wstringstream::str返回一个临时值。一旦你打电话给c_str,它就死了。您正在将指向死牛肉的指针传递到ShellExecute中,并且无论如何都应该使用ShellExecuteEx,如果只是用于错误报告的话。
std::string szArg = "-i " + m_strSign;
ShellExecuteA(NULL, "open", strToolupdater.c_str(), szArg.c_str(), NULL, SW_NORMAL);
std::cout << strToolupdater << " " << szArg << std::endl;
std::wstring szArg = L"-i " + m_strSign;
ShellExecuteW(NULL, L"open", strToolupdater.c_str(), szArg.c_str(), NULL, SW_NORMAL);
std::wcout << strToolupdater << L" " << szArg << std::endl;
std::wstring toWStr(const std::string &s)
{
    std::wstring ret;
    int len = MultiByteToWideChar(0, 0, s.c_str(), s.length(), NULL, 0);
    if (len > 0)
    {
        ret.resize(len);
        MultiByteToWideChar(0, 0, s.c_str(), s.length(), &ret[0], len);
    }
    return ret;
}
std::wstring szToolUpdater = toWStr(strToolupdater);
std::wstring szArg = L"-i " + toWStr(m_strSign);
ShellExecuteW(NULL, L"open", szToolUpdater.c_str(), szArg.c_str(), NULL, SW_NORMAL);
std::wcout << szToolUpdater << L" " << szArg << std::endl;