How to /actually/ open a web page from win32 code?

Discussion in 'Game Development (Technical)' started by Applewood, Oct 8, 2011.

  1. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,858
    Likes Received:
    2
    I'm currently calling this on a button click in my win32 c++ app:

    ShellExecute(NULL,"open",Entry.ShopURL,NULL,NULL,SW_SHOWNORMAL);

    Just like it says in various MS and other websites.

    My problem is that I would like that piece of code to actually open the default browser at the given location, as opposed to nothing happening, getting a 5 return from the call and a debug spew of "First-chance exception at 0x7c812afb in test.exe: 0x80040155: Interface not registered."

    *sigh* Anyone know more than Microsoft about windows programming?

    Thanks! (I'm testing on XP btw)
     
  2. bantamcitygames

    Administrator Original Member Indie Author Greenlit

    Joined:
    Jul 27, 2004
    Messages:
    1,739
    Likes Received:
    80
    Nope, mine looks just like yours...

    ShellExecute(NULL, "open", "http://www.invadazoid.com", NULL, NULL, SW_SHOWMAXIMIZED);

    This seems to work at least for IE and Firefox for me.
     
  3. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,858
    Likes Received:
    2
    Tiresome!

    When I get an ACCESS_DENIED from this call, I fallback to the below which actually works. (Assuming you actually have iexplore)

    ShellExecute(NULL,"open","iexplore",Entry.ShopURL,NULL,SW_SHOWNORMAL);
     
  4. Adrian Lopez

    Original Member

    Joined:
    Sep 7, 2004
    Messages:
    489
    Likes Received:
    0
    Both calls work fine on my system, but here's something you should try, just in case:

    I don't know if that would make any difference in your case (it works fine for me without it), but at least it's something to try.
     
    #4 Adrian Lopez, Oct 8, 2011
    Last edited: Oct 8, 2011
  5. bantamcitygames

    Administrator Original Member Indie Author Greenlit

    Joined:
    Jul 27, 2004
    Messages:
    1,739
    Likes Received:
    80
    Could the access denied be because the user has limited account privileges?
     
  6. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,858
    Likes Received:
    2
    Tried that thanks Adrian, didn't help.

    Bruno, I thought this might be it as well, but I'm on XP with a single full-access account. It's presumably gonna fail even harder for me on Vista, lol
     
  7. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Well, assuming Windows NT or greater, this might work
    Code:
    WinExec("cmd.exe /c start http://maps.google.com/", SW_HIDE);
    
    (cmd.exe is only found in Windows NT and later... :p)
     
  8. Adrian Lopez

    Original Member

    Joined:
    Sep 7, 2004
    Messages:
    489
    Likes Received:
    0
    Could it be a problem with shell32.dll not being properly registered? ShellExecute resides in shell32.dll, so try the following command:

    regsvr32 /i shell32.dll
     
  9. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,858
    Likes Received:
    2
    Tried that as well :(

    It must just be something about my pc, i'll try it on others when I get back to work. Bizarre.
     
  10. cliffski

    Moderator Original Member

    Joined:
    Jul 27, 2004
    Messages:
    3,897
    Likes Received:
    0
    I do this, if it helps?

    void LaunchWebPage(char* url)
    {
    //launches the default browser and sends it to given URL

    SHELLEXECUTEINFO sh;
    memset(&sh, 0L, sizeof(SHELLEXECUTEINFO));

    sh.cbSize = sizeof(SHELLEXECUTEINFO);
    sh.lpVerb = "open";
    sh.lpFile = url;
    sh.nShow = SW_NORMAL;

    if(!ShellExecuteEx(&sh))
    {
    DWORD dw = GetLastError();

    char errorbuffer[256];

    FormatMessage(
    FORMAT_MESSAGE_FROM_SYSTEM,NULL,
    dw,0,
    (LPTSTR)errorbuffer,0,NULL);

    GetDebug()->DebugOut(errorbuffer);
    }
    }
     
  11. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,858
    Likes Received:
    2
    Thanks Cliff, I'll give that a bash shortly.

    Similar result. I actually got an error box from Firefox which at least signifies that Firefox tried to work.
     
    #11 Applewood, Oct 9, 2011
    Last edited: Oct 9, 2011
  12. ManuTOO

    Original Member

    Joined:
    Aug 9, 2004
    Messages:
    344
    Likes Received:
    4
    I use this :
    ShellExecute(MainWindow, "open", "http://www.managames.com", NULL, NULL, Show);
    MainWindow is the HWND to my program window.

    If you did a CoInitialize() before, it won't work, though.
    So in this case, I use :
    ShellExecute(NULL, "open", "Data\\OpenURL.exe", "http://www.managames.com", NULL, SW_HIDE);
    OpenURL.exe is just a lil program that does :
    ShellExecute(MainWindow, "open", pCommand, NULL, NULL, Show);
     
  13. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,858
    Likes Received:
    2
    I think that sounds like the answer, thanks. I do the CoInitialise thing as part of starting up XAudio2.

    Shame it requires such a hack to work though. What a shower, lol
     
  14. cliffski

    Moderator Original Member

    Joined:
    Jul 27, 2004
    Messages:
    3,897
    Likes Received:
    0
    You can't be too hard on microsoft. They have a backwards compatibility nightmare going back to windows 3.11 and before.
    Imagine if you were forced to use the code you wrote fifteen years ago, for your latest project.
    I bet everyone in microsoft would give their right arm for the chance to scrub windows and start again, but it can never happen.
     
  15. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,858
    Likes Received:
    2
    See windows 8 :)
     
  16. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Windows 8 is still the old Win32 API with yet another layer piled on top. I tried the 64bit public beta and i could even run a sample of OpenWatcom (which i installed because the bundled Visual Studio Express somehow couldn't create C/C++ projects) that was written for Win16 :p
     
  17. Applewood

    Moderator Original Member Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    3,858
    Likes Received:
    2
    Oh well. Maybe by windows 9 we'll all be running iOS anyway...
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer