Click to See Complete Forum and Search --> : LPCSTR and WinExec()


Erich J. Ruth
April 29th, 1999, 07:05 PM
The WinExec() function is as follows;

UINT WinExec( LPCSTR lpCmdLine, // address of command line
UINT uCmdShow // window style for new application);
}

If I am running a program from the directory c:\temp how can I execute the file
\windows\notepad.exe. I don't understand how to put the address of the command
line in this LPCSTR variable and I don't understand what kind of variable
LPCSTR is?

Any response is appreciated.

Alvaro
April 29th, 1999, 07:31 PM
LPCSTR is equivalent to a const char*.

It basically means that WinExec expects a character array which won't be changed inside of WinExec. This guarantees you that the array you pass to WinExec will be the same before you call it and after it returns.

The opposite of LPCSTR is LPSTR which is used by functions which do change the character array internally.

Alvaro

Dave Lorde
April 30th, 1999, 06:00 AM
The first place to look to answer this sort of question is the VC++ documentation:

LPCSTR: Same as LPSTR, except used for read-only string pointers. Defined as (const char FAR*).

LPSTR: A 32-bit pointer to a character string

const char cmdLine[] = "\\windows\\notepad.exe";
UINT result = WinExec(cmdLine, SW_SHOW);
if (result < 32)
{
// handle error
}

Dave