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.

286 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. spinterf.cxx
  6. Abstract:
  7. spooler private interfaces (private exports in winspool.drv)
  8. Author:
  9. Lazar Ivanov (LazarI) Jul-05-2000
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. #include "spinterf.hxx"
  15. /*++
  16. Title:
  17. MakePrnPersistError
  18. Routine Description:
  19. converts a PRN_PERSIST HRESULT to a Win32 error
  20. Arguments:
  21. hr - HRESULT to convert
  22. Return Value:
  23. Win32 error code
  24. --*/
  25. DWORD
  26. MakePrnPersistError(HRESULT hr)
  27. {
  28. DWORD err;
  29. if(HRESULT_FACILITY(hr) == static_cast<HRESULT>(FACILITY_ITF))
  30. {
  31. err = ERROR_INVALID_ACCESS;
  32. }
  33. else
  34. {
  35. err = HRESULT_CODE(hr);
  36. }
  37. return err;
  38. };
  39. /*++
  40. Title:
  41. RestorePrinterSettings
  42. Routine Description:
  43. applies stored settings on specified printer
  44. Arguments:
  45. pszPrinterName -- printer name
  46. pszFileName -- file name
  47. flags -- flags that specify which settings to restore
  48. Return Value:
  49. S_OK if succeeded
  50. PRN_PERSIST hresult ( FACILITY_ITF ) returned by IPrnStream::RestorePrinterInfo
  51. Last Error:
  52. ERROR_INVALID_ACCESS if hr is a PRN_PERSIST HRESULT
  53. an Win32 error code if hr is a predefined HRESULT
  54. --*/
  55. HRESULT
  56. RestorePrinterSettings(
  57. IN LPCTSTR pszPrinterName,
  58. IN LPCTSTR pszFileName,
  59. IN DWORD flags
  60. )
  61. {
  62. TStatusB bStatus;
  63. TStatusH hr;
  64. IPrnStream *pIPrnStream = NULL;
  65. CoInitialize( NULL );
  66. hr DBGCHK = CoCreateInstance( CLSID_PrintUIShellExtension, 0, CLSCTX_INPROC_SERVER, IID_IPrnStream, (VOID**)&pIPrnStream );
  67. if( SUCCEEDED( hr ) )
  68. {
  69. hr DBGCHK = pIPrnStream->BindPrinterAndFile(pszPrinterName,pszFileName);
  70. if(SUCCEEDED(hr))
  71. {
  72. hr DBGCHK = pIPrnStream->RestorePrinterInfo(flags);
  73. }
  74. pIPrnStream->Release();
  75. }
  76. CoUninitialize();
  77. if(FAILED(hr))
  78. {
  79. SetLastError(MakePrnPersistError(hr));
  80. }
  81. return hr;
  82. }
  83. /*++
  84. Title:
  85. StorePrinterSettings
  86. Routine Description:
  87. store printer settings into file
  88. Arguments:
  89. pszPrinterName -- printer name
  90. pszFileName -- file name
  91. flags -- specify which settings to store
  92. Return Value:
  93. S_OK if succeeded
  94. PRN_PERSIST hresult ( FACILITY_ITF ) returned by IPrnStream::StorePrinterInfo
  95. Last Error:
  96. ERROR_INVALID_ACCESS if hr is a PRN_PERSIST HRESULT
  97. an Win32 error code if hr is a predefined HRESULT
  98. --*/
  99. HRESULT
  100. StorePrinterSettings(
  101. IN LPTSTR pszPrinterName,
  102. IN LPTSTR pszFileName,
  103. IN DWORD flags
  104. )
  105. {
  106. TStatusB bStatus;
  107. TStatusH hr;
  108. IPrnStream *pIPrnStream = NULL;
  109. CoInitialize( NULL );
  110. hr DBGCHK = CoCreateInstance( CLSID_PrintUIShellExtension, 0, CLSCTX_INPROC_SERVER, IID_IPrnStream, (VOID**)&pIPrnStream );
  111. if( SUCCEEDED( hr ) )
  112. {
  113. hr DBGCHK = pIPrnStream->BindPrinterAndFile(pszPrinterName,pszFileName);
  114. if(SUCCEEDED(hr))
  115. {
  116. hr DBGCHK = pIPrnStream->StorePrinterInfo(flags);
  117. }
  118. pIPrnStream->Release();
  119. }
  120. CoUninitialize();
  121. if(FAILED(hr))
  122. {
  123. SetLastError(MakePrnPersistError(hr));
  124. }
  125. return hr;
  126. }
  127. extern "C"
  128. {
  129. // prototypes of some private APIs exported from splcore.dll
  130. typedef HRESULT WINAPI fnPrintUIWebPnpEntry(LPCTSTR lpszCmdLine);
  131. typedef HRESULT WINAPI fnPrintUIWebPnpPostEntry(BOOL fConnection, LPCTSTR lpszBinFile, LPCTSTR lpszPortName, LPCTSTR lpszPrtName);
  132. typedef HRESULT WINAPI fnPrintUICreateInstance(REFIID riid, void **ppv);
  133. enum
  134. {
  135. // the export ordinals for each function
  136. ordPrintUIWebPnpEntry = 226,
  137. ordPrintUIWebPnpPostEntry = 227,
  138. ordPrintUICreateInstance = 228,
  139. };
  140. } // extern "C"
  141. static HMODULE g_hWinspool = NULL;
  142. static fnPrintUIWebPnpEntry *g_pfnPrintUIWebPnpEntry = NULL;
  143. static fnPrintUIWebPnpPostEntry *g_pfnPrintUIWebPnpPostEntry = NULL;
  144. static fnPrintUICreateInstance *g_pfnPrintUICreateInstance = NULL;
  145. HRESULT Winspool_WebPnpEntry(LPCTSTR lpszCmdLine)
  146. {
  147. return g_pfnPrintUIWebPnpEntry ? g_pfnPrintUIWebPnpEntry(lpszCmdLine) : E_FAIL;
  148. }
  149. HRESULT Winspool_WebPnpPostEntry(BOOL fConnection, LPCTSTR lpszBinFile, LPCTSTR lpszPortName, LPCTSTR lpszPrtName)
  150. {
  151. return g_pfnPrintUIWebPnpPostEntry ? g_pfnPrintUIWebPnpPostEntry(
  152. fConnection, lpszBinFile, lpszPortName, lpszPrtName) : E_FAIL;
  153. }
  154. HRESULT Winspool_CreateInstance(REFIID riid, void **ppv)
  155. {
  156. return g_pfnPrintUICreateInstance ? g_pfnPrintUICreateInstance(riid, ppv) : E_FAIL;
  157. }
  158. // init/shutdown of splcore.dll
  159. HRESULT Winspool_Init()
  160. {
  161. HRESULT hr = E_FAIL;
  162. g_hWinspool = LoadLibrary(TEXT("winspool.drv"));
  163. if( g_hWinspool )
  164. {
  165. g_pfnPrintUIWebPnpEntry = reinterpret_cast<fnPrintUIWebPnpEntry*>(
  166. GetProcAddress(g_hWinspool, (LPCSTR)MAKEINTRESOURCE(ordPrintUIWebPnpEntry)));
  167. g_pfnPrintUIWebPnpPostEntry = reinterpret_cast<fnPrintUIWebPnpPostEntry*>(
  168. GetProcAddress(g_hWinspool, (LPCSTR)MAKEINTRESOURCE(ordPrintUIWebPnpPostEntry)));
  169. g_pfnPrintUICreateInstance = reinterpret_cast<fnPrintUICreateInstance*>(
  170. GetProcAddress(g_hWinspool, (LPCSTR)MAKEINTRESOURCE(ordPrintUICreateInstance)));
  171. if( g_pfnPrintUIWebPnpEntry && g_pfnPrintUIWebPnpPostEntry && g_pfnPrintUICreateInstance )
  172. {
  173. hr = S_OK;
  174. }
  175. else
  176. {
  177. g_pfnPrintUIWebPnpEntry = NULL;
  178. g_pfnPrintUIWebPnpPostEntry = NULL;
  179. g_pfnPrintUICreateInstance = NULL;
  180. FreeLibrary(g_hWinspool);
  181. g_hWinspool = NULL;
  182. }
  183. }
  184. return hr;
  185. }
  186. HRESULT Winspool_Done()
  187. {
  188. if( g_hWinspool )
  189. {
  190. g_pfnPrintUIWebPnpEntry = NULL;
  191. g_pfnPrintUIWebPnpPostEntry = NULL;
  192. g_pfnPrintUICreateInstance = NULL;
  193. FreeLibrary(g_hWinspool);
  194. g_hWinspool = NULL;
  195. }
  196. return S_OK;
  197. }