This question already has answers here:
CreateProcess() fails with an access violation [duplicate]

(3个答案)


3年前关闭。




我正在使用Windows 8 x64 Enterprise,VS2010。

我对CreateProcess()有一些问题。

我创建了一个Win32 Console项目来执行我的应用程序_backround_manipulator.exe

在这里执行。
#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>

DWORD RunManipulator(TCHAR* tszProcessPath);

int _tmain(int argc, _TCHAR* argv[])
{
    _tprintf(_T("---Manipulator will start...---\n"));
    if(0x08 == RunManipulator(_T("_background_manipulator.exe")))
        _tprintf(_T("---Manipulator Started.---\n"));
    else
        _tprintf(_T("---Manipulator cannot run.---\n"));
    return 0;
}

DWORD RunManipulator(TCHAR* tszProcessPath)
{
    STARTUPINFO _v_startupinfo;
    PROCESS_INFORMATION _v_processinfo;
    ZeroMemory(&_v_startupinfo, sizeof(STARTUPINFO));
    ZeroMemory(&_v_processinfo, sizeof(PROCESS_INFORMATION));

    _v_startupinfo.cb = sizeof(STARTUPINFO);

    if (!CreateProcess(NULL, tszProcessPath, NULL, NULL, FALSE, 0, NULL, NULL, &_v_startupinfo, &_v_processinfo));
    {
        return 0x12;
    }

    return 0x08;
}

但是不能在CreateProcess(NULL, tszProcesPath, /*...*/)模式下通过debug函数。

这样的错误;

c&#43;&#43; - CreateProcess()函数无法运行。错误无法写入内存-LMLPHP

我的代码有什么问题?
是因为我创建了控制台项目吗?

最佳答案

如果寻找 CreateProcess 的定义

BOOL WINAPI CreateProcess(
  _In_opt_    LPCTSTR               lpApplicationName,
  _Inout_opt_ LPTSTR                lpCommandLine,
  ...

我们可以注意到lpCommandLine定义为参数中的In,而不定义为const指针(与lpApplicationName相比,它是const指针LP C TSTR)

和:



但您确实将文字字符串 _T("_background_manipulator.exe")传递为lpCommandLine。并获得异常(exception)结果-无法写入内存

关于c++ - CreateProcess()函数无法运行。错误无法写入内存,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46176649/

10-11 22:36