Home » U++ Library support » U++ Core » LaunchWebBrowser() problem and perhaps not the best solution
Re: LaunchWebBrowser() problem and perhaps not the best solution [message #35737 is a reply to message #35731] |
Thu, 15 March 2012 08:41   |
 |
koldo
Messages: 3437 Registered: August 2008
|
Senior Veteran |
|
|
Hello Mirek
In fact WaitForSingleObject() is useless as it always wait the timeout.
However I realized that sometimes the string passed is released BEFORE the thread is really run so second call to ShellExecuteW() fails as LaunchWebBrowser() has ended before .
The proposed solution is this one:
void ShellExecuteOpen(char *str)
{
ShellExecuteW(NULL, L"open", ToSystemCharsetW(str), NULL, L".", SW_SHOWDEFAULT);
free((void *)str);
}
void LaunchWebBrowser(const String& url)
{
if (int(ShellExecuteW(NULL, L"open", ToSystemCharsetW(url), NULL, L".", SW_SHOWDEFAULT)) <= 32) {
char *curl = (char *)malloc(url.GetLength()+1);
strcpy(curl, url);
HANDLE handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&ShellExecuteOpen, (LPVOID)curl, 0, NULL);
if (handle == NULL)
return;
CloseHandle(handle);
}
}
The thread receives the string and releases it.
Best regards
IƱaki
|
|
|
Goto Forum:
Current Time: Tue Jun 17 16:54:28 CEST 2025
Total time taken to generate the page: 0.04923 seconds
|