0
votes

I'm a newbie in c++ and trying to use debug apis, but i can't even start. Because i couldn't run any exe by CreateProcess api. It doesn't give any compile error, but does return false. Do you have any suggestions?

LPCWSTR appName = LPCWSTR("C:\\TEST.EXE");
LPSTARTUPINFO sInfo = LPSTARTUPINFO();
LPPROCESS_INFORMATION pInfo = LPPROCESS_INFORMATION();

if (CreateProcess(appName,NULL,NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,sInfo,pInfo))
{
    printf("done!");
}
else
{
    printf("error!");
}
1
Use GetLastError() to get information about why it failed. - Mark Stevens
87 It gives. I've searched about it and i see that its about arguments, but which one and why :)? - Halil Ibrahim
Yeah, "one or more parameters is incorrect" isn't too useful. Glad someone had the right answer for you. - Mark Stevens

1 Answers

4
votes

sInfo and pInfo are not pointing to valid memory (and error code 87 means The parameter is incorrect.). Change to:

STARTUPINFO sInfo = { sizeof(sInfo };
TCHAR desktop[] = TEXT("winsta0\\default");
sInfo.lpDesktop = desktop;
PROCESS_INFORMATION pInfo;

and pass the addresses of the objects to CreateProcess() (i.e. &sInfo, &pInfo).