Search code examples
c++windowsshellexecute

Why do we need to pass LPCTSTR lpParameters with ShellExecute


Shell Execute has the following signature :

HINSTANCE ShellExecute(
  __in_opt  HWND hwnd,
  __in_opt  LPCTSTR lpOperation,
  __in      LPCTSTR lpFile,
  __in_opt  LPCTSTR lpParameters,
  __in_opt  LPCTSTR lpDirectory,
  __in      INT nShowCmd
);

How can we use lpParameters , Can we handle the parameter in my application. I am executing my app as below:

HINSTANCE hShellExecuteStatus = ShellExecute(NULL, "open", "MyPath/MyApp.EXE", NULL, NULL, SW_SHOWNORMAL);

Can I pass something in the 4th parameter i.e: lpParameters , so that I can handle this with MyApp.Exe , let's say if I am passing "Hi: in the 4th param:

HINSTANCE hShellExecuteStatus = ShellExecute(NULL, "open", "MyPath/MyApp.EXE", "Hi", NULL, SW_SHOWNORMAL);

Can I check in my application whether it is hi and display a message high.

I tried with POSTMESSAGE , but is not helpful with shellexecute


Solution

  • lpParameters will come through in the command line. Use GetCommandLine() to see it.