Thread overview
How to find the Path of Internet Explorer
Jan 07, 2007
Ed Schroder
Jan 07, 2007
Bertel Brander
Jan 07, 2007
Bertel Brander
Jan 08, 2007
Ed Schroder
Feb 13, 2007
Matthew Wilson
January 07, 2007
How can one launch Internet Explorer (or the default browser) from
a console application?

I have it currently running via a hard call from: C:\Progra~1 \Intern~1\iexplore.exe

Fishy code.....

TIA

Ed
January 07, 2007
Ed Schroder skrev:
> How can one launch Internet Explorer (or the default browser) from
> a console application?
> 
> I have it currently running via a hard call from: C:\Progra~1
> \Intern~1\iexplore.exe

Normally you could do:

#include <windows.h>
#include <shlwapi.h>
#include <iostream>
int main()
{
   DWORD Size;
   char Buffer[1024];
   AssocQueryString(0, ASSOCSTR_EXECUTABLE, ".htm", "Open", Buffer, &Size);
   std::cout << "Assoc: " << Buffer << std::endl;
}

But the default version of windows libraries and headerfiles
shipped with Digital Mars does not have shlwapi.h, so you
will need to do some tricks.

In some cases ShellExecute is the answer.

-- 
Just another homepage:
http://damb.dk
But it's mine - Bertel
January 07, 2007
Bertel Brander skrev:
> Ed Schroder skrev:
>> How can one launch Internet Explorer (or the default browser) from
>> a console application?
>>
>> I have it currently running via a hard call from: C:\Progra~1
>> \Intern~1\iexplore.exe
> 
> Normally you could do:
> 
> #include <windows.h>
> #include <shlwapi.h>
> #include <iostream>
> int main()
> {
>    DWORD Size;
>    char Buffer[1024];
>    AssocQueryString(0, ASSOCSTR_EXECUTABLE, ".htm", "Open", Buffer, &Size);
>    std::cout << "Assoc: " << Buffer << std::endl;
> }
> 
> But the default version of windows libraries and headerfiles
> shipped with Digital Mars does not have shlwapi.h, so you
> will need to do some tricks.

One that works with Digital Mars:

#include <cstdlib>
#include <string>
#include <windows.h>
#include <iostream>

typedef DECLSPEC_IMPORT HRESULT WINAPI (*AssocQueryStringType )(DWORD,DWORD,LPCSTR,LPCSTR,LPSTR,DWORD*);

int main()
{
   HMODULE Module = LoadLibrary("shlwapi.dll");
   AssocQueryStringType AssocQueryString = (AssocQueryStringType)GetProcAddress(Module, "AssocQueryStringA");
   if(AssocQueryString)
   {
      char Buffer[1024] = "";
      DWORD Size = sizeof(Buffer);
      AssocQueryString(0, 2, ".htm", "open", Buffer, &Size);
      std::cout << "Assoc: " << Buffer << std::endl;
   }
   else
   {
      std::cout << "No Such proc" << std::endl;
   }
}

-- 
Just another homepage:
http://damb.dk
But it's mine - Bertel
January 08, 2007
You are the greatest...................!

Thx again.

Ed

> One that works with Digital Mars:
> #include <cstdlib>
> #include <string>
> #include <windows.h>
> #include <iostream>
> typedef DECLSPEC_IMPORT HRESULT WINAPI (*AssocQueryStringType
> )(DWORD,DWORD,LPCSTR,LPCSTR,LPSTR,DWORD*);
> int main()
> {
>     HMODULE Module = LoadLibrary("shlwapi.dll");
>     AssocQueryStringType AssocQueryString =
> (AssocQueryStringType)GetProcAddress(Module, "AssocQueryStringA");
>     if(AssocQueryString)
>     {
>        char Buffer[1024] = "";
>        DWORD Size = sizeof(Buffer);
>        AssocQueryString(0, 2, ".htm", "open", Buffer, &Size);
>        std::cout << "Assoc: " << Buffer << std::endl;
>     }
>     else
>     {
>        std::cout << "No Such proc" << std::endl;
>     }
> }

February 13, 2007
"Bertel Brander" <bertel@post4.tele.dk> wrote in message news:enrvf3$f5u$1@digitaldaemon.com...
> Bertel Brander skrev:
> > Ed Schroder skrev:
> >> How can one launch Internet Explorer (or the default browser) from
> >> a console application?
> >>
> >> I have it currently running via a hard call from: C:\Progra~1 \Intern~1\iexplore.exe
> >
> > Normally you could do:
> >
> > #include <windows.h>
> > #include <shlwapi.h>
> > #include <iostream>
> > int main()
> > {
> >    DWORD Size;
> >    char Buffer[1024];
> >    AssocQueryString(0, ASSOCSTR_EXECUTABLE, ".htm", "Open", Buffer,
&Size);
> >    std::cout << "Assoc: " << Buffer << std::endl;
> > }
> >
> > But the default version of windows libraries and headerfiles shipped with Digital Mars does not have shlwapi.h, so you will need to do some tricks.
>
> One that works with Digital Mars:
>
> #include <cstdlib>
> #include <string>
> #include <windows.h>
> #include <iostream>
>
> typedef DECLSPEC_IMPORT HRESULT WINAPI (*AssocQueryStringType
> )(DWORD,DWORD,LPCSTR,LPCSTR,LPSTR,DWORD*);
>
> int main()
> {
>     HMODULE Module = LoadLibrary("shlwapi.dll");
>     AssocQueryStringType AssocQueryString =
> (AssocQueryStringType)GetProcAddress(Module, "AssocQueryStringA");
>     if(AssocQueryString)
>     {
>        char Buffer[1024] = "";
>        DWORD Size = sizeof(Buffer);
>        AssocQueryString(0, 2, ".htm", "open", Buffer, &Size);
>        std::cout << "Assoc: " << Buffer << std::endl;
>     }
>     else
>     {
>        std::cout << "No Such proc" << std::endl;
>     }
> }

You could use dl_call (from the STLSoft sub-project, WinSTL; http://stlsoft.org/), for simpler syntax:

#include <winstl/dl/dl_call.hpp>
#include <winstl/error/error_desc.hpp>
#include <iostream>

int main()
{
    try
    {
        char    Buffer[1024]    =   "";
        DWORD   Size            =   sizeof(Buffer);
        HRESULT hr;

        hr = winstl::dl_call<HRESULT>("SHLWAPI.dll",
"stdcall:AssocQueryStringA", 0, 2, ".htm", "open", &Buffer[0], &Size);

        if(SUCCEEDED(hr))
        {
            std::cout << "Assoc: " << Buffer << std::endl;
        }
        else
        {
            std::cerr << "Failed: " << winstl::error_desc(hr) << std::endl;
        }
    }
    catch(winstl::windows_exception& x)
    {
        std::cerr << "Error: " << x.what() << std::endl;
    }

    return 0;
}


HTH

Matthew