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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...