Re: CreateProcess not work on Vista
- From: "Duy Trinh" <duy.trinh@xxxxxxxxxxx>
- Date: Fri, 27 Apr 2007 09:24:23 +0700
ya, i am sure that ffmpeg.exe is in my folder, coz my app run well on XP,
but i copy that folder to Vista computer, it said that "The parameter is
incorrect".
you type that commandline (the same commandline i ran in my app) in Vista
console, it run well.
"Duy Trinh" <duy.trinh@xxxxxxxxxxx> wrote in message
news:uYmWG%23GiHHA.4516@xxxxxxxxxxxxxxxxxxxxxxx
MAX_LEN = 1024 > MAX_PATH
Error msg said that "System cannot find the file specified.", but the file
i need to run, still exist in my folder.
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:1qg1335umvkv4knla9v5qjms3h3jpjnvi6@xxxxxxxxxx
Define "can't". Whenever you call an API function, and it fails, you
MUST call
::GetLastError() to get the reason; otherwise, it is impossible to
diagnose what is wrong.
What is MAX_LEN? Did you mean perhaps MAX_PATH? Note that if MAX_LEN is
less than
MAX_PATH you can have problems.
On Thu, 26 Apr 2007 15:44:24 +0700, "Duy Trinh" <duy.trinh@xxxxxxxxxxx>
wrote:
hi all****
Pls see code below, i have a problem that if my code is compiled on
None-Unicode mode, it run well, but i compiled on Unicode mode, it can't
run
cmdline (ffmpeg.exe ...) on Vista. Any idea?
CString sCmd;
TCHAR szCmd[MAX_LEN];
TCHAR szDir[MAX_LEN];
GetCurrentDirectory(MAX_LEN, szDir);
USES_CONVERSION;
sCmd.Format(_T("\"%s\\ffmpeg.exe\" -y -i \"%s\" \"%s\""), szDir,
A2T(AVIFile), tFilePath);
_tcscpy(szCmd, sCmd);
Use either StringCchCopy or, if using VS2005, _tcscpy_s, to avoid buffer
overruns. You
are not checking to see if sCmd.GetLength() > MAX_LEN-1, so this has
potential for fatal
consequences.
Using GetBuffer is preferrable to making a copy into a fixed-size buffer,
e.g.,
LPTSTR p = sCmd.GetBuffer();
and after the CreateProcess you must ReleaseBuffer()
****
****
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory (&si, sizeof ( si));
ZeroMemory (&pi, sizeof ( pi));
si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
DWORD bRes = CreateProcess ( NULL, szCmd, NULL, NULL, TRUE,
NORMAL_PRIORITY_CLASS,
GetEnvironmentStrings (), NULL, &si, &pi);
PrintDebug(_T("%s res[%d]"), szCmd, bRes);
(a) why are you waiting if the process didn't start? Why are you not
testing for failure?
(b) why are you not calling ::GetLastError()?
Without knowing the reason for the error, you have no idea why it failed.
It could even
be some issue of Vista security. But without the precise reason being
given, there is no
way to tell.
****
WaitForSingleObject ( pi.hProcess, INFINITE);****
If this is in your main GUI thread, waiting for the process kills the GUI
until the
process finishes. See my essay on asynchronous process notification on
my MVP Tips site
****
CloseHandle( pi.hProcess);****
CloseHandle( pi.hThread);
If the process did not start, these operations are meaningless and must
not be done
(CloseHandle has the undocumented feature that it throws an exception
when given an
illegal handle). Essentially, you MUST ALWAYS assume that operations like
CreateProcess
will fail, and handle such situations.
*****
Joseph M. Newcomer [MVP]
return ( bRes);
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- CreateProcess not work on Vista
- From: Duy Trinh
- Re: CreateProcess not work on Vista
- From: Joseph M . Newcomer
- Re: CreateProcess not work on Vista
- From: Duy Trinh
- CreateProcess not work on Vista
- Prev by Date: Re: Possible reasons for a C++ exception being thrown for line three?
- Next by Date: Re: Modeless dialog box in a thread
- Previous by thread: Re: CreateProcess not work on Vista
- Next by thread: Re: CreateProcess not work on Vista
- Index(es):
Relevant Pages
|