View the DQSD CVS repository here:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dqsd/

Update of /cvsroot/dqsd/dqsd/src/DQSDTools
In directory sc8-pr-cvs1:/tmp/cvs-serv6694/src/DQSDTools

Modified Files:
        Launcher.cpp 
Log Message:
- Fixed resource leak in SetSite (un-closed registry handle)
- Minor optimization: Made all string literals appended to CComBSTR L-prepended, so as 
to avoid an ANSI<->UNICODE conversion.
- Made proper use of T2BSTR in a number of places to return ANSI strings as BSTRs
- Now uses new lengthof macro to determine char buffer length
- Special folders map is now TCHAR correct

Index: Launcher.cpp
===================================================================
RCS file: /cvsroot/dqsd/dqsd/src/DQSDTools/Launcher.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** Launcher.cpp        28 Jun 2003 17:32:03 -0000      1.38
--- Launcher.cpp        29 Jun 2003 14:41:29 -0000      1.39
***************
*** 9,13 ****
  #include <shlobj.h>
  
- 
  #pragma comment(lib, "Version.lib")
  
--- 9,12 ----
***************
*** 18,22 ****
  LPCTSTR CLauncher::DQSD_SEC_KEY = 
_T("CLSID\\{226b64e8-dc75-4eea-a6c8-abcb4d1d37ff}\\SecureFiles");
  
- 
  STDMETHODIMP CLauncher::SetSite(IUnknown* pUnkSite)
  {
--- 17,20 ----
***************
*** 68,71 ****
--- 66,71 ----
        }
  
+       RegCloseKey(hDqsdKey);
+ 
      if (success == FALSE)
        {
***************
*** 77,83 ****
  
    return S_OK;
! };
! 
! 
  
  STDMETHODIMP CLauncher::SubmitForm(VARIANT idForm)
--- 77,81 ----
  
    return S_OK;
! }
  
  STDMETHODIMP CLauncher::SubmitForm(VARIANT idForm)
***************
*** 85,89 ****
        HRESULT hr;
  
- 
        // Check for correct VARIANT type
        if (idForm.vt != VT_DISPATCH)
--- 83,86 ----
***************
*** 119,123 ****
  
        // Retrieve FORM from DOM, manipulate target window, and get HTML text
!       CComBSTR bstrTarget(_T("_self"));
        spFormElement->put_target(bstrTarget);
        CComBSTR bstrHTML;
--- 116,120 ----
  
        // Retrieve FORM from DOM, manipulate target window, and get HTML text
!       CComBSTR bstrTarget(L"_self");
        spFormElement->put_target(bstrTarget);
        CComBSTR bstrHTML;
***************
*** 127,136 ****
        // Dump HTML text in temp file
        {
!               DWORD cbPath = _MAX_PATH;
                DWORD dwBytesWritten;
                TCHAR szPath[_MAX_PATH];
!               ::GetTempPath(cbPath, szPath);
  
!               StrNCat(szPath, _T("DQSDLaunch.html"), 
sizeof(szPath)/sizeof(TCHAR)-_tcslen(szPath)-1);
                HANDLE hFile = ::CreateFile(szPath, GENERIC_WRITE, FILE_SHARE_READ, 
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
                if (hFile == INVALID_HANDLE_VALUE)
--- 124,133 ----
        // Dump HTML text in temp file
        {
!               DWORD cchPath = _MAX_PATH;
                DWORD dwBytesWritten;
                TCHAR szPath[_MAX_PATH];
!               ::GetTempPath(cchPath, szPath);
  
!               StrNCat(szPath, _T("DQSDLaunch.html"), lengthof(szPath) - 
_tcslen(szPath) - 1);
                HANDLE hFile = ::CreateFile(szPath, GENERIC_WRITE, FILE_SHARE_READ, 
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
                if (hFile == INVALID_HANDLE_VALUE)
***************
*** 141,151 ****
                CComBSTR bstrOutput, bstrBanner;
                bstrBanner.LoadString(IDS_BANNER);
!               bstrOutput.Append(_T("<html><body onload=\"document."));
                bstrOutput.Append(bstrFormName);
!               bstrOutput.Append(_T(".submit();\">\n"));
                bstrOutput.Append(bstrBanner);
!               bstrOutput.Append(_T("\n"));
                bstrOutput.Append(bstrHTML);
!               bstrOutput.Append(_T("\n</body></html>\n"));
                ::WriteFile(hFile, OLE2T(bstrOutput), bstrOutput.Length(), 
&dwBytesWritten, NULL);
                ::FlushFileBuffers(hFile);
--- 138,148 ----
                CComBSTR bstrOutput, bstrBanner;
                bstrBanner.LoadString(IDS_BANNER);
!               bstrOutput.Append(L"<html><body onload=\"document.");
                bstrOutput.Append(bstrFormName);
!               bstrOutput.Append(L".submit();\">\n");
                bstrOutput.Append(bstrBanner);
!               bstrOutput.Append(L"\n");
                bstrOutput.Append(bstrHTML);
!               bstrOutput.Append(L"\n</body></html>\n");
                ::WriteFile(hFile, OLE2T(bstrOutput), bstrOutput.Length(), 
&dwBytesWritten, NULL);
                ::FlushFileBuffers(hFile);
***************
*** 153,157 ****
                ::CloseHandle(hFile);
  
- 
                // Open html associated application, passing DQSDLaunch.html
                HINSTANCE hInstance = ::ShellExecute(NULL, NULL, szPath, NULL, NULL, 
SW_SHOWNORMAL);
--- 150,153 ----
***************
*** 163,167 ****
  }
  
- 
  STDMETHODIMP CLauncher::OpenDocument(BSTR strDoc, VARIANT* pvParameters)
  {
--- 159,162 ----
***************
*** 185,190 ****
  }
  
- 
- 
  STDMETHODIMP CLauncher::get_pathDefaultBrowser(BSTR *pVal)
  {
--- 180,183 ----
***************
*** 197,201 ****
        // Create temp file with desired .html extension
        ::GetTempPath(cbDocPath, szDocPath);
!       StrNCat(szDocPath, _T("DQSDLaunch.html"), 
sizeof(szDocPath)/sizeof(TCHAR)-_tcslen(szDocPath)-1);
        HANDLE hFile = ::CreateFile(szDocPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, 
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hFile == INVALID_HANDLE_VALUE)
--- 190,194 ----
        // Create temp file with desired .html extension
        ::GetTempPath(cbDocPath, szDocPath);
!       StrNCat(szDocPath, _T("DQSDLaunch.html"), lengthof(szDocPath) - 
_tcslen(szDocPath) - 1);
        HANDLE hFile = ::CreateFile(szDocPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, 
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hFile == INVALID_HANDLE_VALUE)
***************
*** 209,213 ****
        
        // Prepare string for shipping, and ship
!       *pVal = ::SysAllocString(T2OLE(szExePath));
  
        return S_OK;
--- 202,206 ----
        
        // Prepare string for shipping, and ship
!       *pVal = T2BSTR(szExePath);
  
        return S_OK;
***************
*** 233,237 ****
  }
  
- 
  STDMETHODIMP CLauncher::ReadFile(BSTR bstrFilename, BSTR *pbstrResult)
  {
--- 226,229 ----
***************
*** 283,322 ****
                HRESULT_FROM_WIN32(::GetLastError());
  
        DWORD dwBytesWritten = 0;
!       BOOL bResult = ::WriteFile( hFile, W2CT( bstrValue ), lstrlenW( bstrValue ), 
&dwBytesWritten, NULL );
        ::FlushFileBuffers( hFile );
        ::CloseHandle( hFile );
        
        if ( 0 == bResult )
!               HRESULT_FROM_WIN32(::GetLastError());
! 
!       return S_OK;
! }
! 
! // Private methods
! 
! HRESULT CLauncher::GetFilename( LPCTSTR szName, LPTSTR szResult, LPCTSTR 
pszDefaultExt /*= _T(".txt")*/ )
! {
!       USES_CONVERSION;
! 
!       // Get the installation directory from the registry
!       CRegKey rk;
!       if ( ERROR_SUCCESS != rk.Open( HKEY_CLASSES_ROOT, DQSD_REG_KEY, KEY_READ ) )
!       {
!               Error(IDS_ERR_REGKEYNOTFOUND, IID_ILauncher);
!               return E_UNEXPECTED;
!       }
! 
!       TCHAR szInstallDir[ _MAX_PATH ];
!       DWORD dwCount = sizeof( szInstallDir );
!       if ( ERROR_SUCCESS != rk.QueryValue( szInstallDir, _T("InstallDir"), &dwCount 
) )
!       {
!               Error(IDS_ERR_REGKEYNOTFOUND, IID_ILauncher);
!               return E_UNEXPECTED;
!       }
! 
!       // Add the install directory and an extension if not supplied
!       ::PathCombine( szResult, szInstallDir, szName );
!       ::PathAddExtension( szResult, pszDefaultExt );
  
        return S_OK;
--- 275,287 ----
                HRESULT_FROM_WIN32(::GetLastError());
  
+       // TODO: Avoid using conversion macros here -- it's dangerous, 
+       // since there's no telling how large bstrValue is
        DWORD dwBytesWritten = 0;
!       BOOL bResult = ::WriteFile( hFile, W2CT( bstrValue ), SysStringLen(bstrValue), 
&dwBytesWritten, NULL );
        ::FlushFileBuffers( hFile );
        ::CloseHandle( hFile );
        
        if ( 0 == bResult )
!               return HRESULT_FROM_WIN32(::GetLastError());
  
        return S_OK;
***************
*** 328,333 ****
  
        TCHAR szProtocolHandlerKey[ 128 ];
!       StrCpyN( szProtocolHandlerKey, W2T( bstrProtocol ), 
sizeof(szProtocolHandlerKey)/sizeof(TCHAR));
!       StrNCat( szProtocolHandlerKey, _T("\\shell\\open\\command"), 
sizeof(szProtocolHandlerKey)/sizeof(TCHAR)-lstrlenW(bstrProtocol)-1);
  
        TCHAR szProtocolHandler[ _MAX_PATH ];
--- 293,298 ----
  
        TCHAR szProtocolHandlerKey[ 128 ];
!       StrCpyN( szProtocolHandlerKey, W2CT( bstrProtocol ), 
lengthof(szProtocolHandlerKey));
!       StrNCat( szProtocolHandlerKey, _T("\\shell\\open\\command"), 
lengthof(szProtocolHandlerKey) - SysStringLen(bstrProtocol) - 1);
  
        TCHAR szProtocolHandler[ _MAX_PATH ];
***************
*** 343,347 ****
        }
  
!       *pbstrHandler = ::SysAllocString( T2W( szProtocolHandler ) );
  
        return S_OK;
--- 308,312 ----
        }
  
!       *pbstrHandler = T2BSTR(szProtocolHandler);
  
        return S_OK;
***************
*** 378,382 ****
                        continue;
  
!               bstrFiles.Append( _T("\n") );
                bstrFiles.Append( fd.cFileName );
        }
--- 343,347 ----
                        continue;
  
!               bstrFiles.Append( L"\n" );
                bstrFiles.Append( fd.cFileName );
        }
***************
*** 415,419 ****
  }
  
- 
  STDMETHODIMP CLauncher::get_VersionIsCorrect(int v1, int v2, int v3, int v4, 
VARIANT_BOOL *pVal)
  {
--- 380,383 ----
***************
*** 519,523 ****
  }
  
- 
  __declspec(dllexport) void CALLBACK RestartExplorer(HWND hParent, HINSTANCE hInst, 
LPTSTR lpCmdLine, int nShow)
  {
--- 483,486 ----
***************
*** 527,533 ****
        UNREFERENCED_PARAMETER(nShow);
  
!       HWND hwndShell = FindWindow("Progman", NULL);
        ::PostMessage(hwndShell, WM_QUIT, 0, 0L);
!       ::WinExec("Explorer.exe",SW_SHOW);
  }
  
--- 490,496 ----
        UNREFERENCED_PARAMETER(nShow);
  
!       HWND hwndShell = FindWindow(_T("Progman"), NULL);
        ::PostMessage(hwndShell, WM_QUIT, 0, 0L);
!       ::WinExec("Explorer.exe", SW_SHOW);
  }
  
***************
*** 553,557 ****
  }
  
- 
  STDMETHODIMP CLauncher::ShutdownBar(LPDISPATCH pDispDocument)
  {
--- 516,519 ----
***************
*** 634,640 ****
        }
  
!       CComBSTR bstrInstallDir;
!       bstrInstallDir.Append(szInstallDir);
!       *pbstrDirectory = bstrInstallDir.Detach();
        return S_OK;
  }
--- 596,600 ----
        }
  
!       *pbstrDirectory = T2BSTR(szInstallDir);
        return S_OK;
  }
***************
*** 647,659 ****
  static SPECIAL_FOLDER_MAP_T SpecialFolders[] =
  {
!       {"AppData",             CSIDL_APPDATA},
!       {"Desktop",             CSIDL_DESKTOP},
!       {"Favorites",           CSIDL_FAVORITES},
!       {"History",             CSIDL_HISTORY},
!       {"MyDocuments",         CSIDL_PERSONAL},
!       {"Recent",              CSIDL_RECENT},
!       {"StartMenu",           CSIDL_STARTMENU}
  };
! #define SpecialFoldersCount  (sizeof(SpecialFolders) / sizeof(SPECIAL_FOLDER_MAP_T))
  
  STDMETHODIMP CLauncher::GetSpecialFolderLocation(BSTR bstrSpecialFolder, BSTR* 
pbstrLocation)
--- 607,619 ----
  static SPECIAL_FOLDER_MAP_T SpecialFolders[] =
  {
!       {_T("AppData"),             CSIDL_APPDATA},
!       {_T("Desktop"),             CSIDL_DESKTOP},
!       {_T("Favorites"),           CSIDL_FAVORITES},
!       {_T("History"),             CSIDL_HISTORY},
!       {_T("MyDocuments"),         CSIDL_PERSONAL},
!       {_T("Recent"),              CSIDL_RECENT},
!       {_T("StartMenu"),           CSIDL_STARTMENU}
  };
! #define SpecialFoldersCount  (lengthof(SpecialFolders))
  
  STDMETHODIMP CLauncher::GetSpecialFolderLocation(BSTR bstrSpecialFolder, BSTR* 
pbstrLocation)
***************
*** 689,695 ****
        }
  
!       CComBSTR bstrLocation;
!       bstrLocation.Append(szPath);
!       *pbstrLocation = bstrLocation.Detach();
        return S_OK;
  }
--- 649,654 ----
        }
  
!       *pbstrLocation = T2BSTR(szPath);
! 
        return S_OK;
  }
***************
*** 725,729 ****
                        continue;
  
!               bstrFolders.Append( _T("\n") );
                bstrFolders.Append( fd.cFileName );
        }
--- 684,688 ----
                        continue;
  
!               bstrFolders.Append( L"\n" );
                bstrFolders.Append( fd.cFileName );
        }
***************
*** 837,840 ****
--- 796,800 ----
  }
  
+ // Private methods
  HRESULT CLauncher::GetInstallationDirectory( LPTSTR szResult, DWORD dwResultSize)
  {
***************
*** 875,877 ****
--- 835,864 ----
        int nCommonPathLen = ::PathCommonPrefix(szCanonDir, szCanonFilename, NULL);
        return (nCommonPathLen == (int)_tcslen(szCanonDir)) ? TRUE : FALSE;
+ }
+ 
+ HRESULT CLauncher::GetFilename( LPCTSTR szName, LPTSTR szResult, LPCTSTR 
pszDefaultExt /*= _T(".txt")*/ )
+ {
+       USES_CONVERSION;
+ 
+       // Get the installation directory from the registry
+       CRegKey rk;
+       if ( ERROR_SUCCESS != rk.Open( HKEY_CLASSES_ROOT, DQSD_REG_KEY, KEY_READ ) )
+       {
+               Error(IDS_ERR_REGKEYNOTFOUND, IID_ILauncher);
+               return E_UNEXPECTED;
+       }
+ 
+       TCHAR szInstallDir[ _MAX_PATH ];
+       DWORD dwCount = sizeof( szInstallDir );
+       if ( ERROR_SUCCESS != rk.QueryValue( szInstallDir, _T("InstallDir"), &dwCount 
) )
+       {
+               Error(IDS_ERR_REGKEYNOTFOUND, IID_ILauncher);
+               return E_UNEXPECTED;
+       }
+ 
+       // Add the install directory and an extension if not supplied
+       ::PathCombine( szResult, szInstallDir, szName );
+       ::PathAddExtension( szResult, pszDefaultExt );
+ 
+       return S_OK;
  }




-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
DQSD-CVS mailing list
https://lists.sourceforge.net/lists/listinfo/dqsd-cvs
DQSD CVS repository:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dqsd/

Reply via email to