Re: CreateProcess not work on Vista

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
*****

return ( bRes);

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm




.



Relevant Pages

  • Re: AppPath and Vista
    ... single user it's their personal App Data folder. ... EXE you can get Vista to require authorization ... Dim sBuffer As String, hToken As Long ...
    (comp.lang.basic.visual.misc)
  • Re: filename is too long or contains illegal caracters
    ... which version of Vista are you using? ... past told me they don't know anything about Publisher). ... Do you upload to a particular folder on ... Per you suggestion, I tried to Add a Network Location in "Computer", ...
    (microsoft.public.publisher.webdesign)
  • Re: filename is too long or contains illegal caracters
    ... I have been working with Microsoft Publisher Support about this problem ... can drag and drop my files onto the web site. ... which version of Vista are you using? ... Do you upload to a particular folder ...
    (microsoft.public.publisher.webdesign)
  • Re: Read/Write permission (earn your quarter, Karl!)
    ... Assuming the OS is Vista and my apps folder in Program Files is read only. ... helper app updated both the exe and the helper app exe. ... Inno install package that just does an install over the existing ...
    (microsoft.public.vb.general.discussion)
  • Re: filename is too long or contains illegal caracters
    ... Do you upload to a particular folder on your ... Per you suggestion, I tried to Add a Network Location in "Computer", but I ... The only difference is Vista. ... Open Publisher & create & save in normal way. ...
    (microsoft.public.publisher.webdesign)