Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.8 KiB

  1. /*-----------------------------------------------------------------------------
  2. dlapi.cpp
  3. Wrapper for softlinking to download DLL
  4. Copyright (C) 1996 Microsoft Corporation
  5. All rights reserved.
  6. Authors:
  7. ChrisK ChrisKauffman
  8. History:
  9. 7/22/96 ChrisK Cleaned and formatted
  10. -----------------------------------------------------------------------------*/
  11. #include "pch.hpp"
  12. #include "debug.h"
  13. #include "icwdl.h"
  14. #include "dlapi.h"
  15. // ############################################################################
  16. CDownLoadAPI::CDownLoadAPI()
  17. {
  18. m_hDLL = NULL;
  19. m_pfnDownLoadInit = NULL;
  20. m_pfnDownLoadCancel = NULL;
  21. m_pfnDownLoadExecute = NULL;
  22. m_pfnDownLoadClose = NULL;
  23. m_pfnDownLoadSetStatus = NULL;
  24. m_pfnDownLoadProcess = NULL;
  25. }
  26. // ############################################################################
  27. CDownLoadAPI::~CDownLoadAPI()
  28. {
  29. if (m_hDLL) FreeLibrary(m_hDLL);
  30. m_hDLL = NULL;
  31. m_pfnDownLoadInit = NULL;
  32. m_pfnDownLoadCancel = NULL;
  33. m_pfnDownLoadExecute = NULL;
  34. m_pfnDownLoadClose = NULL;
  35. m_pfnDownLoadSetStatus = NULL;
  36. m_pfnDownLoadProcess = NULL;
  37. }
  38. // ############################################################################
  39. HRESULT CDownLoadAPI::LoadAPI(LPSTR szApiName, FARPROC* pfp)
  40. {
  41. Assert(szApiName && pfp);
  42. if (!m_hDLL)
  43. m_hDLL = LoadLibrary(DOWNLOAD_LIBRARY);
  44. if (m_hDLL && !(*pfp))
  45. {
  46. *pfp = GetProcAddress(m_hDLL, szApiName);
  47. if (*pfp)
  48. return ERROR_SUCCESS;
  49. else
  50. return GetLastError();
  51. } else {
  52. return GetLastError();
  53. }
  54. }
  55. // ############################################################################
  56. HRESULT CDownLoadAPI::DownLoadInit(PTSTR pszUrl, DWORD_PTR * lpCDialingDlg, DWORD_PTR *lpdwDownload, HWND hwndParent)
  57. {
  58. HRESULT hr = ERROR_DLL_NOT_FOUND;
  59. LoadAPI(DOWNLOADINIT,(FARPROC*)&m_pfnDownLoadInit);
  60. if (m_pfnDownLoadInit)
  61. hr = (m_pfnDownLoadInit)(pszUrl, lpCDialingDlg, lpdwDownload, hwndParent);
  62. return hr;
  63. }
  64. // ############################################################################
  65. HRESULT CDownLoadAPI::DownLoadCancel(DWORD_PTR dwDownload)
  66. {
  67. HRESULT hr = ERROR_DLL_NOT_FOUND;
  68. LoadAPI(DOWNLOADCANCEL,(FARPROC*)&m_pfnDownLoadCancel);
  69. if (m_pfnDownLoadCancel)
  70. hr = (m_pfnDownLoadCancel)(dwDownload);
  71. return hr;
  72. }
  73. // ############################################################################
  74. HRESULT CDownLoadAPI::DownLoadExecute(DWORD_PTR dwDownload)
  75. {
  76. HRESULT hr = ERROR_DLL_NOT_FOUND;
  77. LoadAPI(DOWNLOADEXECUTE,(FARPROC*)&m_pfnDownLoadExecute);
  78. if (m_pfnDownLoadExecute)
  79. hr = (m_pfnDownLoadExecute)(dwDownload);
  80. return hr;
  81. }
  82. // ############################################################################
  83. HRESULT CDownLoadAPI::DownLoadProcess(DWORD_PTR dwDownload)
  84. {
  85. HRESULT hr = ERROR_DLL_NOT_FOUND;
  86. LoadAPI(DOWNLOADPROCESS,(FARPROC*)&m_pfnDownLoadProcess);
  87. if (m_pfnDownLoadProcess)
  88. hr = (m_pfnDownLoadProcess)(dwDownload);
  89. return hr;
  90. }
  91. // ############################################################################
  92. HRESULT CDownLoadAPI::DownLoadClose(DWORD_PTR dwDownload)
  93. {
  94. HRESULT hr = ERROR_DLL_NOT_FOUND;
  95. LoadAPI(DOWNLOADCLOSE,(FARPROC*)&m_pfnDownLoadClose);
  96. if (m_pfnDownLoadClose)
  97. hr = (m_pfnDownLoadClose)(dwDownload);
  98. return hr;
  99. }
  100. // ############################################################################
  101. HRESULT CDownLoadAPI::DownLoadSetStatus(DWORD_PTR dwDownload, INTERNET_STATUS_CALLBACK fnCallback)
  102. {
  103. HRESULT hr = ERROR_DLL_NOT_FOUND;
  104. LoadAPI(DOWNLOADSETSTATUS,(FARPROC*)&m_pfnDownLoadSetStatus);
  105. if (m_pfnDownLoadSetStatus)
  106. // jmazner 10/2/96 Normandy # 8493
  107. // ICWDL.DLL's DownLoadSetStatus only has two parameters!!!
  108. //hr = (m_pfnDownLoadSetStatus)(dwDownload, fnCallback, dwContext);
  109. hr = (m_pfnDownLoadSetStatus)(dwDownload, fnCallback);
  110. return hr;
  111. }