我收到错误代码2,无法找到该文件。但我已经尝试了完整的路径而没有。 我已经没有运气让这个过程开始,我不知道我的错误是什么,有人可以指出它吗?CreateProcess将无法启动
这是全码:
#include "stdafx.h"
#include <map>
#include <psapi.h>
#include "shlwapi.h"
#define ERROR_FILE_NOT_FOUND = 2;
void Debug(char* path[])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
char* p = path[0];
char* args = path[1];
int dwProcess = CreateProcess((LPCWSTR)p, (LPWSTR)args, NULL, NULL, false, DEBUG_ONLY_THIS_PROCESS, NULL, NULL, &si, &pi);
if (!dwProcess)
{
DWORD dwLastErrorCode = GetLastError();
printf("Error: %d", dwLastErrorCode);
}
DEBUG_EVENT debug_event = {0};
DWORD dwContinueStatus = DBG_CONTINUE;
DWORD dwResume = DBG_EXCEPTION_HANDLED;
while (!WaitForDebugEvent(&debug_event, INFINITE))
{
switch(debug_event.dwDebugEventCode)
{
case EXCEPTION_DEBUG_EVENT:
{
EXCEPTION_DEBUG_INFO& exception = debug_event.u.Exception;
if (exception.ExceptionRecord.ExceptionCode == 0x0EEDFADE && exception.dwFirstChance)
dwContinueStatus = dwResume;
}
}
ContinueDebugEvent(debug_event.dwProcessId, debug_event.dwThreadId, dwContinueStatus);
}
}
int main(char* argv[])
{
char* p[2] = { "Notepad.exe", "args" };
Debug(p);
return 0;
}
任何帮助表示赞赏。
你有没有尝试执行错误检查?这是你应该做的第一件事。在你这样做之后,你可能会意识到哪些参数导致了麻烦,以及为什么尽你所能编译代码是一个坏主意。这是一个开始:*如果函数失败,返回值为零。要获得扩展错误信息,请致电GetLastError。* – chris
需要为notepad.exe提供绝对路径? – billz
@billz,你不应该为notepad.exe。它通常位于PATH覆盖的目录中。 – chris