Game Development Community

OpenWebBrowser

by Howard Dortch · in Torque Game Engine · 08/18/2005 (4:41 pm) · 19 replies

I searched the forums and found some data on how to open a web browser but mine fails as so:

Failed to open the HKCR\http registry key!!!

There was a fix listed referencing "openWebBrowser" in the engine but the only reference is for UNIX platform.

Anyone let me know how to open a browser at a web site from within a game ?

#1
08/18/2005 (4:45 pm)
OOps spelling error found the windows one but still doesn't work.
#2
08/24/2005 (3:21 pm)
I'm getting this problem too...

Any clues?
#3
08/24/2005 (3:45 pm)
Does the registry key HKEY_CLASSES_ROOT\http\shell\open\command exists?

What is your default browser?

Are you playing with UNICODE stuff?
#4
08/24/2005 (3:57 pm)
It looks like there may be a bug related to this resource.

I'll look more closely at it later, but I'm guessing after you solve the registry problem openWebBrowser will only work the first time:

in engine/platformWin32/winWindow.cc
RegCloseKey( regKey );
      sHaveKey = true;

      char *p = dStrstr(sWebKey, "\"%1\"");
      if (p) *p = 0;
      }

      STARTUPINFO si;
      dMemset( &si, 0, sizeof( si ) );
      si.cb = sizeof( si );

      char buf[1024];
      dSprintf( buf, sizeof( buf ), "%s %s", (const char*) sWebKey, webAddress );

should probably be
RegCloseKey( regKey );
      sHaveKey = true;
      } // <-- I moved this

      char *p = dStrstr(sWebKey, "\"%1\"");
      if (p) *p = 0;

      STARTUPINFO si;
      dMemset( &si, 0, sizeof( si ) );
      si.cb = sizeof( si );

      char buf[1024];
      dSprintf( buf, sizeof( buf ), "%s %s", (const char*) sWebKey, webAddress );
#5
08/24/2005 (6:41 pm)
I was wrong about the "%1" problem... the code is correct.

Thought I'd also add that the console functions name is gotoWebPage() to prevent any confusion.
#6
08/24/2005 (6:45 pm)
Looks good. I'll review this. #327.
#7
08/24/2005 (6:46 pm)
Oh. Well then. XD
#8
08/24/2005 (8:11 pm)
So I've been playing with the code and it seems to work fine. The only scenario in which I've been able to create the error you are asking about, Howarth & Jason, is if I delete or rename registry key.

So I did a little research and this is what I learned. According to Microsoft in this [url=]ttp://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B224816] kb article[/url] ShellExecute is a preferred way to launch a web browser or url. It is supported all the way back to Microsoft Windows NT 3.1. This might solve your problem. All you have to do is replace engine/platformWin32/winWindow.cc Platform::openWebBrowser() with:

bool Platform::openWebBrowser( const char* webAddress )
{
     ShellExecute(NULL, "open", webAddress, NULL, NULL, SW_SHOWNORMAL);

     Return (true);
}

One thing to note is that the webaddress you supply must have the "http://" part or it will not understand that you are opening a web page.

Also note from Microsoft
Quote: The Launch folder windows in a separate process setting in Folder Options affects ShellExecute. If that option is disabled (the default setting), ShellExecute uses an open Explorer window rather than launch a new one. If no Explorer window is open, ShellExecute launches a new one.
This means by default it will use an already open browser, not launch a new one.

Hope this helps.
#9
08/24/2005 (8:34 pm)
So I'm on a roll tonight. Turns out that ShellExecute relies on the same registry key entries, and therfore probably will not work for you. Argggg...
#10
08/25/2005 (5:04 am)
My Registry entry is as follows

HKEY_CLASSES_ROOT\http\shell\open\command ""C\PROGRA~1\INTERN~\iecplore.exe" -nohome"

That help any ?
#11
08/25/2005 (8:11 am)
Hmmm.... interesting.

What OS are you using?

Did you perhaps make a typo? Looks like the exe name is misspelled? "iecplore.exe" should be "iexplore.exe" .

I'll mess around some more and get back to you.

Edit: I also just noticed that the : is missing in the 'C:\' part.
#12
08/25/2005 (9:04 am)
So when you look at the key what is its named?

For example when I goto the HKEY_CLASSES_ROOT\http\shell\open\command key I see one string value:

Name: (Default)
Type: REG_SZ
Value: "C:\Program Files\Internet Explorer\iexplore.exe" -nohome
#13
08/25/2005 (9:05 am)
This box has 98SE on it and yeah mis spell on the c:\ and iexplore, couldn't copy/paste from regedit
#14
08/25/2005 (10:07 am)
All I have is Name:(Default) and Data ""C:\Program Files\Internet Explorer\iexplore.exe" -nohome"
note the extra set of quotes there.
There is no Type in the listing.
#15
08/25/2005 (10:30 am)
Well, you have the key in there correctly, but the error is reporting that it can't find the key. I'm kind of stumped because the line of code that is failing doesn't have many paths to disaster.

if ( RegOpenKeyEx( HKEY_CLASSES_ROOT, "\http\shell\open\command", 0, KEY_QUERY_VALUE, &regKey ) != ERROR_SUCCESS )
{
   Con::errorf( ConsoleLogEntry::General, "Failed to open the HKCR\http registry key!!!");
   return( false );
}

So basically all that is left is:

1) The process/user Torque is running under doesn't have permission to read the key. If that's true lots of other applications should be having problems.
2) There is some sort of strange bug in RegOpenKeyEx, this seems unlikely.
3) Could be that the values for HKEY_CLASSES_ROOT, KEY_QUERY_VALUE or ERROR_SUCCESS have been messed with. Have you done anything like that?
#16
08/25/2005 (10:58 am)
You can have it open Internet Explorer by default if no key is found.
#17
08/25/2005 (11:23 am)
@Mike - Problem is you'd have to assume where it is located, and believe it or not but some OEM's remove IE, but it might make a nice option of last resort.
#18
08/25/2005 (11:42 am)
@Mike I may try that just to see it work.
@Philip other applications I have open the browser. Word for instance, if I click on a www.whatever.com in word or other applications it opens and runs fine. Gota love a mystery......
#19
08/25/2005 (12:07 pm)
Is it "pop-up" blocker perhaps?