-1

I made a program using Win32Api. In the program, it has "ShellExecute" phrase in order to execute chrome for searching. Following is a abstraction fo what i wrote.

#include <windows.h>
#include <shellapi.h>
int main () {
    ShellExecute(NULL, L"open", searching_url, NULL, NULL, SW_SHOWMAXIMIZED);
}

It works in my computer. But, I sent this windows app to other people and they said it doesn't work. I mean only shellexecute doesn't work. I cannot catch where to start figuring out what's wrong here.

Would you please suggest How I figure it out in structured way? Thanks.

mogandaz
  • 1
  • 2
  • Check the return value (have your program display it and get the other people to tell you what it is), this will give you more info about why execution failed. [Reference for return value](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx) – M.M Jan 21 '16 at 04:17
  • @M.M return value from ShellExecute is probably useless. To get proper error handling use ShellExecuteEx. – David Heffernan Jan 21 '16 at 07:06
  • Does ShellExecute show an error ? Did you check the return value of ShellExecute? – Jabberwocky Jan 21 '16 at 09:03
  • Thanks for all comments and answers. I changed L"open" to NULL and it works out ! But still I'm not sure why it did in that way. – mogandaz Jan 21 '16 at 14:04
  • Because as Jonathan Potter pointed, is possible that verb "open" not exist. – user2120666 Jan 21 '16 at 15:31

1 Answers1

5

Two things to try:

  • ShellExecute can require COM to be initialized under certain circumstances. The docs for the ShellExecute function explain why in more detail. You should call CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) before the call to ShellExecute and CoUninitialize() afterwards.
  • Instead of using L"open" as the verb, you should generally use NULL. NULL will always give you the "default" action for an object (equivalent to double-clicking it) which is not always "open".
Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79