CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    5

    LPCSTR and WinExec()

    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.




  2. #2
    Join Date
    Apr 1999
    Location
    Miami, FL
    Posts
    67

    Re: LPCSTR and WinExec()

    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

  3. #3
    Join Date
    Apr 1999
    Posts
    383

    Re: LPCSTR and WinExec()

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured