c++ - How to find the Path of Internet Explorer
- Ed Schroder (7/7) Jan 07 2007 How can one launch Internet Explorer (or the default browser) from
- Bertel Brander (20/25) Jan 07 2007 Normally you could do:
- Bertel Brander (29/52) Jan 07 2007 One that works with Digital Mars:
- Ed Schroder (3/27) Jan 07 2007 You are the greatest...................!
- Matthew Wilson (34/82) Feb 13 2007 &Size);
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
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.exeNormally 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 skrev:Ed Schroder skrev: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 - BertelHow 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.exeNormally 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.
Jan 07 2007
You are the greatest...................! Thx again. EdOne 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
"Bertel Brander" <bertel post4.tele.dk> wrote in message news:enrvf3$f5u$1 digitaldaemon.com...Bertel Brander skrev:&Size);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.exeNormally 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,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 Matthewstd::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; } }
Feb 13 2007