www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



c++ - How to find the Path of Internet Explorer

↑ ↓ ← Ed Schroder <matador home.nl> writes:
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
Jan 07 2007
↑ ↓ Bertel Brander <bertel post4.tele.dk> writes:
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
Jan 07 2007
↑ ↓ Bertel Brander <bertel post4.tele.dk> writes:
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
Jan 07 2007
→ Ed Schroder <matador home.nl> writes:
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;
     }
 }

Jan 07 2007
→ "Matthew Wilson" <matthew hat.stlsoft.dot.org> writes:
"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,


    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
Feb 13 2007