Opening URL under Wine

note This article available in Russian.

Imagine the following situation. Our product can detect if it is running under WineHQ already. And, indeed, our product has many places from which we must open URL’s:

  • information about the product,
  • checking for updates,
  • online help,
  • technical support page
  • and so on.

Trying to call ShellExecute head-on, passing the URL as parameter, and … Nothing happens!

The thing is that Wine, honestly emulating everything, wants to start a web browser not installed in the system, but installed under the Wine. There are no any browsers installed yet. Therefore, nothing happens.

Of course, you can install the browser, but why not open the required documents in their native system applications? This raises the question of interaction of the Wine and the operating system.

There are a number of commands available in Wine.

We are interested in winebrowser command, which opens the URL in the native operating system application. And taking into account that URL can refer to the file, we have really serious mechanism in our hands.

winebrowser httр://www.winehq.org

winebrowser ftp://ftp.winehq.org

winebrowser irc://irc.freenode.net/#winehq

winebrowser file://c:\\windows\\win.ini

On a KDE system the first two might open in Konqueror, the third in Konversation, and the last in KWrite.

As a result, applying the function GetWineAvail (), described earlier, our code might look like this:

//Delphi Code

procedure OpenUrl(url: string);
var
  S: string;
begin
  if GetWineAvail() then 
    S := 'winebrowser ' + url
  else
    S := url;
  ShellExecute(0, 'open', PChar(S), nil, nil, SW_SHOW);
end;

...
  OpenURL('mailto:support@microolap.com?Subject=PgMDD:%20Support');
  OpenURL('httр://microolap.com/products/database/postgresql-designer/');
...

or like this:

//C Code
void OpenUrl(char * url);
{
    char s[255];
    if (GetWineAvail())
    {
        strcpy(s, "winebrowser ");
        strcat(s, url);
    }
    else
    {
        strcpy(s, url);
    }
    
    ShellExecute(NULL"open", s, NULLNULL, SW_SHOW);
}

...
  OpenURL("mailto:support@microolap.com?Subject=PgMDD:%20Support");
  OpenURL("httр://microolap.com/products/database/postgresql-designer/");
...

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s