28 if( (
NULL == pszInURL ) || (
NULL == ppszOutURL ) )
30 return( E_INVALIDARG );
36 BOOL fNeedFilePrefix = ( 0 == wcsstr( pszInURL, L
"://" ) );
41 LPWSTR pszTemp = pszInURL;
46 LPWSTR pchToEscape = wcspbrk( pszTemp, L
" #$%&\\+,;=@[]^{}" );
48 if(
NULL == pchToEscape )
55 pszTemp = pchToEscape + 1;
61 int cchNeeded = wcslen( pszInURL ) + ( 2 * cEscapees ) + 1;
68 *ppszOutURL =
new WCHAR[ cchNeeded ];
70 if(
NULL == *ppszOutURL )
72 return( E_OUTOFMEMORY );
80 LPWSTR pchNext = *ppszOutURL;
90 LPWSTR pchToEscape = wcspbrk( pszTemp, L
" #$%&\\+,;=@[]^{}" );
92 if(
NULL == pchToEscape )
97 wcscpy( pchNext, pszTemp );
104 int cchToCopy = pchToEscape - pszTemp;
108 wcsncpy( pchNext, pszTemp, cchToCopy );
110 pchNext += cchToCopy;
116 pchNext += swprintf( pchNext, L
"%%%02x", *pchToEscape );
118 pszTemp = pchToEscape + 1;
131 HKEY hFileKey =
NULL;
140 TCHAR szFileType[ MAX_PATH ];
142 lResult = RegOpenKeyEx( HKEY_CLASSES_ROOT, _T(
".html" ), 0, KEY_READ, &hKey );
144 if( ERROR_SUCCESS != lResult )
149 DWORD dwLength =
sizeof( szFileType );
151 lResult = RegQueryValueEx( hKey,
NULL, 0,
NULL, (
BYTE *)szFileType, &dwLength );
153 if( ERROR_SUCCESS != lResult )
161 TCHAR szKeyName[ MAX_PATH + 20 ];
163 wsprintf( szKeyName, _T(
"%s\\shell\\open\\command" ), szFileType );
165 lResult = RegOpenKeyEx( HKEY_CLASSES_ROOT, szKeyName, 0, KEY_READ, &hFileKey );
167 if( ERROR_SUCCESS != lResult )
172 dwLength = cbShellOpenCommand;
174 lResult = RegQueryValueEx( hFileKey,
NULL, 0,
NULL, (
BYTE *)ptszShellOpenCommand, &dwLength );
178 fFoundExtensionCommand =
TRUE;
187 if( !fFoundExtensionCommand )
199 lResult = RegOpenKeyEx( HKEY_CLASSES_ROOT, _T(
"http\\shell\\open\\command" ), 0, KEY_READ, &hKey );
201 if( ERROR_SUCCESS != lResult )
206 DWORD dwLength = cbShellOpenCommand;
208 lResult = RegQueryValueEx( hKey,
NULL, 0,
NULL, (
BYTE *)ptszShellOpenCommand, &dwLength );
218 if(
NULL != hFileKey )
220 RegCloseKey( hFileKey );
223 return( HRESULT_FROM_WIN32( lResult ) );
235 TCHAR szShellOpenCommand[ MAX_PATH * 2 ];
247 TCHAR szLaunchCommand[ 2000 ];
249 LPTSTR pszParam = _tcsstr( szShellOpenCommand, _T(
"\"%1\"" ) );
251 if(
NULL == pszParam )
253 pszParam = _tcsstr( szShellOpenCommand, _T(
"\"%*\"" ) );
256 if(
NULL != pszParam )
258 *pszParam = _T(
'\0' ) ;
260 wsprintf( szLaunchCommand, _T(
"%s%ws%s" ), szShellOpenCommand, pszURL, pszParam + 4 );
264 wsprintf( szLaunchCommand, _T(
"%s %ws" ), szShellOpenCommand, pszURL );
270 TCHAR szExe[ MAX_PATH * 2 ];
271 LPTSTR pchFirst = szShellOpenCommand;
272 LPTSTR pchNext =
NULL;
274 while( _T(
' ' ) == *pchFirst )
279 if( _T(
'"' ) == *pchFirst )
283 pchNext = _tcschr( pchFirst, _T(
'"' ) );
287 pchNext = _tcschr( pchFirst + 1, _T(
' ' ) );
290 if(
NULL == pchNext )
292 pchNext = szShellOpenCommand + _tcslen( szShellOpenCommand );
295 _tcsncpy( szExe, pchFirst, pchNext - pchFirst );
296 szExe[ pchNext - pchFirst ] = _T(
'\0' ) ;
307 PROCESS_INFORMATION ProcInfo;
308 ZeroMemory( (
LPVOID)&ProcInfo,
sizeof( PROCESS_INFORMATION ) );
311 ZeroMemory( (
LPVOID)&StartUp,
sizeof( STARTUPINFO ) );
313 StartUp.cb =
sizeof(STARTUPINFO);
315 if( !CreateProcess( szExe, szLaunchCommand,
NULL,
NULL,
318 hr = HRESULT_FROM_WIN32( GetLastError() );
326 if(
NULL != ProcInfo.hThread )
328 CloseHandle( ProcInfo.hThread );
331 if(
NULL != ProcInfo.hProcess )
333 CloseHandle( ProcInfo.hProcess );