Home » U++ Library support » U++ Core » LaunchWebBrowser() problem and perhaps not the best solution
LaunchWebBrowser() problem and perhaps not the best solution [message #35714] |
Wed, 14 March 2012 11:40 |
|
koldo
Messages: 3358 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
In my XP LaunchWebBrowser() does not work because of ShellExecute.
A possible solution proposed here ( http://stackoverflow.com/questions/1193873/which-reasons-cou ld-make-shellexecute-fail) is to create a separate thread for executing ShellExecute.
The reason could be this one(Calling Shell Functions and Interfaces from a Multithreaded Apartment: http://support.microsoft.com/?scid=kb%3Ben-us%3B287087&x =16&y=15).
The solution works for me. First call to ShellExecuteOpen() fails but second one in a separate thread, works.
However I am not sure if it is a right implementation. Please check it before approve.
#if defined(PLATFORM_WIN32) && !defined(PLATFORM_WINCE)
bool ShellExecuteOpen(const char *str)
{
return 32 < int(ShellExecuteW(NULL, L"open", ToSystemCharsetW(str), NULL, L".", SW_SHOWDEFAULT));
}
void LaunchWebBrowser(const String& url)
{
if (!ShellExecuteOpen(url)) {
HANDLE handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&ShellExecuteOpen, (LPVOID)~url, 0, NULL);
if (handle == NULL)
return;
WaitForSingleObject(handle, 500);
CloseHandle(handle);
}
}
#endif
Best regards
IƱaki
|
|
|
Goto Forum:
Current Time: Mon Apr 29 02:04:43 CEST 2024
Total time taken to generate the page: 0.03427 seconds
|