【发布时间】:2018-02-20 22:21:58
【问题描述】:
我使用的是 Windows 8 x64 Enterprise,VS2010。
我在CreateProcess() 上遇到了一些问题。
我创建了一个 Win32 控制台项目来执行 _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;
}
但在debug模式下无法通过CreateProcess(NULL, tszProcesPath, /*...*/)函数。
错误像这样;
我的代码有什么问题? 是因为我创建了控制台项目吗?
【问题讨论】:
-
您是否尝试过使用调试器一步一步地找出导致错误的行?
-
我无法传递 CreateProcess 函数。
-
1)
if后面有分号,我猜这不是我们想要的行为。 2)在失败报告ERROR_FILE_NOT_FOUND的情况下添加GetLastError。路径中有_background_manipulator.exe吗? -
您的
tszProcesPath是只读的。这里不清楚什么?小错误 -
像“_background_manipulator.exe”这样的字符串文字通常在只读部分放置.rdata
标签: c++ visual-studio-2010 winapi console-application createprocess