Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

c++ - CreateProcess() Error

STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
si.cb = sizeof(si);

LPCWSTR procName =(LPCWSTR)"D:\test dir 1\Calc.exe";
LPWSTR procArg   =(LPWSTR)"blacknull";

if(CreateProcess(procName,procArg,0,0,0,CREATE_DEFAULT_ERROR_MODE,0,0,&si,&pi))
{
    //do some work
}

printf( "CreateProcess failed (%d).
", GetLastError());
     system("Pause");

It keeps throwing Error(2)-> The System cannot find the file specified.

I don't know what's wrong. I also tried to use "Calc.exe" which in the same Dir. but it's not working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You use the L prefix to make a wide character string:

L"D:\test dir 1\Calc.exe";

Casting a string literal to a different character width does not make a string wider.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...