(C++ windows) Open default web browser
thx it works perfectly but the app freezes for like 4 seconds then the browser (yeah even firefox) opens ...
greets,
Halan
edit: only if i call it at the beginning of my app so thats no problem
greets,
Halan
edit: only if i call it at the beginning of my app so thats no problem
My Blog: http://www.freakybytes.org
I found a bug with this, appName should be the *second* parameter of CreateProcess, not the first, this was causing it to use ShellExecute every time
Probably why it was freezing for you Halan! Also with CreateProcess working you don't seem to have any problems with firewalls (ZoneAlarm asked you for permission before)
(updated code)
(updated code)
I found another bug in your code yesterday and it is so evil that I won't completely spoil the fun telling you what it is. I just give the lines:
gcc with -Wall will also spoil the fun.
Code: Select all
// otherwise if no quotes, 2nd point is the first space after the last \\
else
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
No freezing...
*Edit - Forgot to close thread handle
Just so we're clear on proper procedure...
Write Code -> Post Code -> Test Code -> Edit Post
Code: Select all
static DWORD WINAPI _RunApp_ThreadProc( LPVOID pData )
{
TCHAR *pUrl = (TCHAR*)pData;
if ( !pUrl ) return -1;
// Lowest priority
::SetThreadPriority( ::GetCurrentThread(), THREAD_PRIORITY_LOWEST );
// Start app
BOOL bSuccess =
( ( (DWORD)::ShellExecute( NULL, "open", pUrl, NULL, NULL, SW_SHOWNORMAL ) ) > 32 );
delete [] pUrl;
if ( !bSuccess )
return -2;
return 0;
}
BOOL RunApp_NoFreeze( LPCTSTR pUrl )
{
if ( !pUrl || !*pUrl )
return FALSE;
TCHAR *pUrlBuf = new TCHAR[ _tcslen( pUrl ) + 1 ];
strcpy( pUrlBuf, pUrl );
// Create a thread
DWORD dwThreadId = 0;
HANDLE hThread = ::CreateThread( (LPSECURITY_ATTRIBUTES)NULL,
0,
_RunApp_ThreadProc,
(LPVOID)pUrlBuf,
0,
&dwThreadId );
if ( NULL == hThread )
return FALSE;
::CloseHandle( hThread );
return TRUE;
}
Just so we're clear on proper procedure...
Write Code -> Post Code -> Test Code -> Edit Post
This is unnecessarily complex... here is the code which does the same thing. It works on all versions of Windows
Simple and easy. 
Code: Select all
string url = "http://irrlicht.sf.net";
system("iexplore " + url);
Genius, pure genius.3ddev wrote:This is unnecessarily complex... here is the code which does the same thing. It works on all versions of WindowsSimple and easy.Code: Select all
string url = "http://irrlicht.sf.net"; system("iexplore " + url);
@Bob: You still should use CreateProcess instead of ShellExecute. I think. Does CreateProcess even freeze?
I didn't try CreateProcess(), because ShellExecute() opens URLs directly, and always uses the default browser.
You can just do this ... but will likely freeze until the page opens.
I've used the thread template above for lots of things, dowloading files, copying huge files, etc... usually eliminates freezing 
You can just do this ... but will likely freeze until the page opens.
Code: Select all
ShellExecute( NULL, "open", "http://irrlicht.sourceforge.net", NULL, NULL, SW_SHOWNORMAL )
