Source code of Windows XP (NT5)
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.

198 lines
4.8 KiB

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