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.

200 lines
5.0 KiB

  1. // DSPrintQueue.cpp : Implementation of CDSPrintQueue
  2. #include "stdafx.h"
  3. #include <strsafe.h>
  4. #include "oleprn.h"
  5. #include "DSPrintQ.h"
  6. #include "winsprlp.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CDSPrintQueue
  9. STDMETHODIMP CDSPrintQueue::InterfaceSupportsErrorInfo(REFIID riid)
  10. {
  11. static const IID* arr[] =
  12. {
  13. &IID_IDSPrintQueue,
  14. };
  15. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  16. {
  17. if (InlineIsEqualGUID(*arr[i],riid))
  18. return S_OK;
  19. }
  20. return S_FALSE;
  21. }
  22. CDSPrintQueue::CDSPrintQueue()
  23. {
  24. m_bstrContainer = NULL;
  25. m_bstrName = NULL;
  26. m_bstrUNCName = NULL;
  27. m_bstrADsPath = NULL;
  28. m_pfnPublishPrinter = (BOOL (*)(HWND, PCWSTR, PCWSTR, PCWSTR, PWSTR *, DWORD)) NULL;
  29. m_hWinspool = NULL;
  30. }
  31. CDSPrintQueue::~CDSPrintQueue()
  32. {
  33. SysFreeString(m_bstrContainer);
  34. SysFreeString(m_bstrName);
  35. SysFreeString(m_bstrUNCName);
  36. SysFreeString(m_bstrADsPath);
  37. if (!m_hWinspool)
  38. FreeLibrary(m_hWinspool);
  39. }
  40. STDMETHODIMP CDSPrintQueue::get_UNCName(BSTR * ppVal)
  41. {
  42. HRESULT hr = S_OK;
  43. if (!ppVal) {
  44. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_PARAMETER);
  45. } else if (m_bstrUNCName) {
  46. if (!(*ppVal = SysAllocString(m_bstrUNCName)))
  47. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_ENOUGH_MEMORY);
  48. } else {
  49. *ppVal = NULL;
  50. }
  51. return hr;
  52. }
  53. STDMETHODIMP CDSPrintQueue::put_UNCName(BSTR newVal)
  54. {
  55. HRESULT hr = S_OK;
  56. if (!newVal)
  57. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_PARAMETER);
  58. if (!(m_bstrUNCName = SysAllocString(newVal)))
  59. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_ENOUGH_MEMORY);
  60. return hr;
  61. }
  62. STDMETHODIMP CDSPrintQueue::get_Name(BSTR * ppVal)
  63. {
  64. HRESULT hr = S_OK;
  65. if (!ppVal) {
  66. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_PARAMETER);
  67. } else if (m_bstrName) {
  68. if (!(*ppVal = SysAllocString(m_bstrName)))
  69. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_ENOUGH_MEMORY);
  70. } else {
  71. *ppVal = NULL;
  72. }
  73. return hr;
  74. }
  75. STDMETHODIMP CDSPrintQueue::put_Name(BSTR newVal)
  76. {
  77. HRESULT hr = S_OK;
  78. if (!newVal)
  79. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_PARAMETER);
  80. if (!(m_bstrName = SysAllocString(newVal)))
  81. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_ENOUGH_MEMORY);
  82. return hr;
  83. }
  84. STDMETHODIMP CDSPrintQueue::get_Container(BSTR * ppVal)
  85. {
  86. HRESULT hr = S_OK;
  87. if (!ppVal) {
  88. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_PARAMETER);
  89. } else if (m_bstrContainer) {
  90. if (!(*ppVal = SysAllocString(m_bstrContainer)))
  91. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_ENOUGH_MEMORY);
  92. } else {
  93. *ppVal = NULL;
  94. }
  95. return hr;
  96. }
  97. STDMETHODIMP CDSPrintQueue::put_Container(BSTR newVal)
  98. {
  99. HRESULT hr = S_OK;
  100. if (!newVal)
  101. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_PARAMETER);
  102. if (!(m_bstrContainer = SysAllocString(newVal)))
  103. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_ENOUGH_MEMORY);
  104. return hr;
  105. }
  106. STDMETHODIMP CDSPrintQueue::Publish(DWORD dwAction)
  107. {
  108. DWORD dwRet = ERROR_SUCCESS;
  109. PWSTR pszADsPath = NULL;
  110. // Load PublishPrinter
  111. if (!m_pfnPublishPrinter) {
  112. if (!m_hWinspool && !(m_hWinspool = LoadLibraryFromSystem32(L"Winspool.drv")))
  113. return SetScriptingError(CLSID_DSPrintQueue, IID_IDSPrintQueue, GetLastError());
  114. if (!(m_pfnPublishPrinter = (BOOL (*)(HWND, PCWSTR, PCWSTR, PCWSTR, PWSTR *, DWORD))
  115. GetProcAddress(m_hWinspool, (LPCSTR) 217)))
  116. return SetScriptingError(CLSID_DSPrintQueue, IID_IDSPrintQueue, GetLastError());
  117. }
  118. // Publish the Printer
  119. if (!m_pfnPublishPrinter((HWND) NULL, m_bstrUNCName, m_bstrContainer, m_bstrName, &pszADsPath, dwAction)) {
  120. dwRet = GetLastError();
  121. if (pszADsPath) {
  122. if (dwAction == PUBLISHPRINTER_FAIL_ON_DUPLICATE && dwRet == ERROR_FILE_EXISTS)
  123. m_bstrADsPath = SysAllocString(pszADsPath);
  124. GlobalFree(pszADsPath);
  125. }
  126. } else if (pszADsPath) {
  127. m_bstrADsPath = SysAllocString(pszADsPath);
  128. GlobalFree(pszADsPath);
  129. }
  130. return SetScriptingError(CLSID_DSPrintQueue, IID_IDSPrintQueue, dwRet);
  131. }
  132. STDMETHODIMP CDSPrintQueue::get_Path(BSTR * ppVal)
  133. {
  134. HRESULT hr = S_OK;
  135. if (!ppVal) {
  136. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_PARAMETER);
  137. } else if (m_bstrADsPath) {
  138. if (!(*ppVal = SysAllocString(m_bstrADsPath)))
  139. hr = MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, ERROR_NOT_ENOUGH_MEMORY);
  140. } else {
  141. *ppVal = NULL;
  142. }
  143. return hr;
  144. }