Unhandled Error with CreateProcess [duplicate]

本小妞迷上赌 提交于 2019-12-01 06:02:39
ervinbosenbacher

The problem is that the second parameter of the CreateProcess function is an in/out parameter.

If you specify it as a string like you did, it is a constant string and the function when it is called cannot write to the memory location, thus you have a memory access violation. The correct way is to call your function like this:

LPTSTR szCmdline = _tcsdup(TEXT("C:\\Windows\\Notepad.exe"));

//create child process
if (!CreateProcess(NULL,
    szCmdline,
    NULL,
    NULL,
    FALSE,
    0,
    NULL,
    NULL,
    &si,
    &pi))
{
    fprintf(stderr, "create process failed");

    return -1;
}

You may also want to read this blog article.

The 2nd arg to CreateProcess cannot be const or a literal string because the func attempts to modify the string. Copy the literal to a local array and then pass that as the 2nd arg.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!