Click to See Complete Forum and Search --> : ShellExecute


stuey
May 16th, 1999, 07:15 PM
hi, im using BorlandC++Builder.. which im guessing is the same as the rest of the C++ family for the ShellExecute command..
my problem is that the ShellExecute command requires a constant value to be entered... ie.. c:\\test.exe how would i declare a variable or item that could be placed within the ShellExecute command to run a file.. such as a value extracted from an ini file.

Thanx a lot

stuey

Playman Cheng
May 17th, 1999, 06:09 AM
Using a string variable in the ShellExecute doesn't work? I don't believe it,just like following:
char pszCh[30]="C:\\Windows\\Pbrush.exe";
ShellExecute(NULL,"Open",pszCh,NULL,NULL,SW_SHOW);

May 18th, 1999, 03:49 AM
sprintf(var1,"%s+%s",var2,var3);
sprintf(pFileTADDIR,"command.com /C T:\\%s\\upd",var1);
if(!CreateProcess(NULL,pFileTADDIR,NULL,NULL,FALSE,
CREATE_DEFAULT_ERROR_MODE, // creation flags
NULL,NULL,&si,&pi ))

Dave Lorde
May 18th, 1999, 04:11 AM
All the string arguments to ShellExecute are LPCTSTR, so you can pass char*, const char*, CString, TCHAR*, etc.

A constant string argument does not mean a literal string argument, it just means the function contracts not to change the string. You can pass non-const strings if you want to.

Here's a cutting from a working program:

CString mode = GetExecuteMode();
CString filePath = GetDocument()->GetFilePath();
// [code removed]
int result = (int)ShellExecute(AfxGetMainWnd()->GetSafeHwnd(), mode, filePath, 0, 0, SW_SHOWNORMAL);

Dave