PDA

View Full Version : ShellExecuteEx path question. [modified] (fixed)



Bsbosa.com
07-09-2010, 01:20 PM
Edit : Issue was mostly with the spawned EXE that did not handled parameters properly.

Now everything is working ok.

Thanks.

I'm trying to figure out a couple of issues I have with some path that contains spaces when using ShellExecuteEx :

The current directory contains space : C:\Users\me\Documents\Visual Studio 2008\Projects\asdcasd\asdcasd
TCHAR Buffer[MAX_PATH];
DWORD dwRet;
dwRet = GetCurrentDirectory(MAX_PATH, Buffer);

// wrap the path with quotes
CString sWorkingPath;
sWorkingPath.Format( _T("\"%s\""), Buffer );

CString command ( _T("XMLtoPDF.exe"));
CString parameters( _T("")); // /noopen
// wrap the path with quotes.
CString sExe;
sExe.Format ( _T("\"%s\\%s\""), Buffer, command);

SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = _T("open");
ShExecInfo.lpFile = sExe;
ShExecInfo.lpParameters = parameters;
ShExecInfo.lpDirectory = sWorkingPath;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);

The exe spawns a console (it's a perl byte-compiled stand-alone) and tells me the path is not good : C:\Users\me\Documents\Visual does not exists.

I've checked the path and they all semms to be double-quoted to handle the spaces.

Am i missing something ?
Thanks a bunch.
Watched code never compiles.
modified on Thursday, July 8, 2010 3:52 PM