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.

467 lines
10 KiB

  1. /*++
  2. Copyright (c) 1996-2003 Microsoft Corporation
  3. Module Name:
  4. comoem.cpp
  5. Abstract:
  6. Implementation of OEMGetInfo and OEMDevMode.
  7. Shared by all Unidrv OEM test dll's.
  8. Environment:
  9. Windows 2000, , Windows XP, Windows Server 2003 Unidrv driver
  10. Revision History:
  11. Created it.
  12. --*/
  13. #include "stddef.h"
  14. #include "stdlib.h"
  15. #include "objbase.h"
  16. #include <windows.h>
  17. #include <assert.h>
  18. #include <prsht.h>
  19. #include <compstui.h>
  20. #include <winddiui.h>
  21. #include <printoem.h>
  22. #include <initguid.h>
  23. #include <prcomoem.h>
  24. #include "oemcomui.h"
  25. #include "ttyui.h"
  26. #include "debug.h"
  27. #include "name.h"
  28. #include <strsafe.h>
  29. // Globals
  30. static HMODULE g_hModule = NULL ; // DLL module handle
  31. static long g_cComponents = 0 ; // Count of active components
  32. static long g_cServerLocks = 0 ; // Count of locks
  33. ////////////////////////////////////////////////////////////////////////////////
  34. //
  35. // IOemCB body
  36. //
  37. HRESULT __stdcall IOemCB::QueryInterface(const IID& iid, void** ppv)
  38. {
  39. VERBOSE(DLLTEXT("IOemCB:QueryInterface entry.\n\n"));
  40. if (iid == IID_IUnknown)
  41. {
  42. *ppv = static_cast<IUnknown*>(this);
  43. VERBOSE(DLLTEXT("IOemCB:Return pointer to IUnknown.\n\n"));
  44. }
  45. else if (iid == IID_IPrintOemUI)
  46. {
  47. *ppv = static_cast<IPrintOemUI*>(this) ;
  48. VERBOSE(DLLTEXT("IOemCB:Return pointer to IPrintOemUI.\n"));
  49. }
  50. else
  51. {
  52. *ppv = NULL ;
  53. WARNING(DLLTEXT("IOemCB:No Interface. Return NULL.\n"));
  54. return E_NOINTERFACE ;
  55. }
  56. reinterpret_cast<IUnknown*>(*ppv)->AddRef() ;
  57. return S_OK ;
  58. }
  59. ULONG __stdcall IOemCB::AddRef()
  60. {
  61. VERBOSE(DLLTEXT("IOemCB:AddRef entry.\n"));
  62. return InterlockedIncrement(&m_cRef) ;
  63. }
  64. ULONG __stdcall IOemCB::Release()
  65. {
  66. VERBOSE(DLLTEXT("IOemCB:Release entry.\n"));
  67. ASSERT( 0 != m_cRef);
  68. ULONG cRef = InterlockedDecrement(&m_cRef);
  69. if (0 == cRef)
  70. {
  71. delete this;
  72. }
  73. return cRef;
  74. }
  75. IOemCB::~IOemCB()
  76. {
  77. //
  78. // Make sure that driver's helper function interface is released.
  79. //
  80. if(NULL != pOEMHelp)
  81. {
  82. pOEMHelp->Release();
  83. pOEMHelp = NULL;
  84. }
  85. //
  86. // If this instance of the object is being deleted, then the reference
  87. // count should be zero.
  88. //
  89. assert (0 == m_cRef) ;
  90. }
  91. LONG __stdcall IOemCB::PublishDriverInterface(
  92. IUnknown *pIUnknown)
  93. {
  94. VERBOSE(DLLTEXT("IOemCB::PublishDriverInterface() entry.\r\n"));
  95. //
  96. // Need to store pointer to Driver Helper functions, if we already haven't.
  97. //
  98. if (this->pOEMHelp == NULL)
  99. {
  100. HRESULT hResult;
  101. //
  102. // Get Interface to Helper Functions.
  103. //
  104. hResult = pIUnknown->QueryInterface(IID_IPrintOemDriverUI, (void** ) &(this->pOEMHelp));
  105. if(!SUCCEEDED(hResult))
  106. {
  107. //
  108. // Make sure that interface pointer reflects interface query failure.
  109. //
  110. this->pOEMHelp = NULL;
  111. }
  112. }
  113. if (this->pOEMHelp)
  114. return S_OK;
  115. else
  116. return S_FALSE;
  117. }
  118. LONG __stdcall IOemCB::GetInfo(
  119. DWORD dwMode,
  120. PVOID pBuffer,
  121. DWORD cbSize,
  122. PDWORD pcbNeeded)
  123. {
  124. VERBOSE(DLLTEXT("IOemCB:GetInfo entry.\n\n"));
  125. if (OEMGetInfo(dwMode, pBuffer, cbSize, pcbNeeded))
  126. return S_OK;
  127. else
  128. return S_FALSE;
  129. }
  130. LONG __stdcall IOemCB::DevMode(
  131. DWORD dwMode,
  132. POEMDMPARAM pOemDMParam)
  133. {
  134. VERBOSE(DLLTEXT("IOemCB:DevMode entry.\n\n"));
  135. return E_NOTIMPL;
  136. }
  137. LONG __stdcall IOemCB::CommonUIProp(
  138. DWORD dwMode,
  139. POEMCUIPPARAM pOemCUIPParam)
  140. {
  141. VERBOSE(DLLTEXT("IOemCB:CommonUIProp entry.\n\n"));
  142. return E_NOTIMPL;
  143. }
  144. LONG __stdcall IOemCB::DocumentPropertySheets(
  145. PPROPSHEETUI_INFO pPSUIInfo,
  146. LPARAM lParam)
  147. {
  148. VERBOSE(DLLTEXT("IOemCB:DocumentPropertySheets entry.\n\n"));
  149. return E_NOTIMPL;
  150. }
  151. LONG __stdcall IOemCB::DevicePropertySheets(
  152. PPROPSHEETUI_INFO pPSUIInfo,
  153. LPARAM lParam)
  154. {
  155. VERBOSE(DLLTEXT("IOemCB:DevicePropertySheets entry.\n\n"));
  156. if(OEMDevicePropertySheets(pPSUIInfo, lParam) == 1)
  157. return S_OK;
  158. return S_FALSE;
  159. }
  160. LONG __stdcall IOemCB::DeviceCapabilities(
  161. POEMUIOBJ poemuiobj,
  162. HANDLE hPrinter,
  163. PWSTR pDeviceName,
  164. WORD wCapability,
  165. PVOID pOutput,
  166. PDEVMODE pPublicDM,
  167. PVOID pOEMDM,
  168. DWORD dwOld,
  169. DWORD *dwResult)
  170. {
  171. VERBOSE(DLLTEXT("IOemCB:DeviceCapabilities entry.\n"));
  172. return E_NOTIMPL;
  173. }
  174. LONG __stdcall IOemCB::DevQueryPrintEx(
  175. POEMUIOBJ poemuiobj,
  176. PDEVQUERYPRINT_INFO pDQPInfo,
  177. PDEVMODE pPublicDM,
  178. PVOID pOEMDM)
  179. {
  180. VERBOSE(DLLTEXT("IOemCB:DevQueryPrintEx entry.\n\n"));
  181. return E_NOTIMPL;
  182. }
  183. LONG __stdcall IOemCB::UpgradePrinter(
  184. DWORD dwLevel,
  185. PBYTE pDriverUpgradeInfo)
  186. {
  187. VERBOSE(DLLTEXT("IOemCB:UpgradePrinter entry.\n\n"));
  188. return E_NOTIMPL;
  189. }
  190. LONG __stdcall IOemCB::PrinterEvent(
  191. PWSTR pPrinterName,
  192. INT iDriverEvent,
  193. DWORD dwFlags,
  194. LPARAM lParam)
  195. {
  196. VERBOSE(DLLTEXT("IOemCB:PrinterEvent entry.\n\n"));
  197. return E_NOTIMPL;
  198. }
  199. LONG __stdcall IOemCB::DriverEvent(
  200. DWORD dwDriverEvent,
  201. DWORD dwLevel,
  202. LPBYTE pDriverInfo,
  203. LPARAM lParam)
  204. {
  205. VERBOSE(DLLTEXT("IOemCB:DriverEvent entry.\n"));
  206. return E_NOTIMPL;
  207. };
  208. LONG __stdcall IOemCB::QueryColorProfile(
  209. HANDLE hPrinter,
  210. POEMUIOBJ poemuiobj,
  211. PDEVMODE pPublicDM,
  212. PVOID pOEMDM,
  213. ULONG ulReserved,
  214. VOID *pvProfileData,
  215. ULONG *pcbProfileData,
  216. FLONG *pflProfileData)
  217. {
  218. VERBOSE(DLLTEXT("IOemCB:QueryColorProfile entry.\n"));
  219. return E_NOTIMPL;
  220. };
  221. //
  222. // UpdateExternalFonts
  223. //
  224. LONG __stdcall IOemCB::UpdateExternalFonts(
  225. HANDLE hPrinter,
  226. HANDLE hHeap,
  227. PWSTR pwstrCartridges)
  228. {
  229. VERBOSE(DLLTEXT("IOemCB:UpdateExternalFonts entry.\n\n"));
  230. return E_NOTIMPL;
  231. };
  232. HRESULT __stdcall IOemCB::FontInstallerDlgProc(
  233. HWND hWnd,
  234. UINT usMsg,
  235. WPARAM wParam,
  236. LPARAM lParam
  237. )
  238. {
  239. VERBOSE(DLLTEXT("IOemCB:FontInstallerDlgProc entry.\n"));
  240. return E_NOTIMPL;
  241. };
  242. ////////////////////////////////////////////////////////////////////////////////
  243. //
  244. // oem class factory
  245. //
  246. class IOemCF : public IClassFactory
  247. {
  248. public:
  249. // *** IUnknown methods ***
  250. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj);
  251. STDMETHOD_(ULONG,AddRef) (THIS);
  252. STDMETHOD_(ULONG,Release) (THIS);
  253. // *** IClassFactory methods ***
  254. STDMETHOD(CreateInstance) (THIS_
  255. LPUNKNOWN pUnkOuter,
  256. REFIID riid,
  257. LPVOID FAR* ppvObject);
  258. STDMETHOD(LockServer) (THIS_ BOOL bLock);
  259. // Constructor
  260. IOemCF(): m_cRef(1) { };
  261. ~IOemCF() { };
  262. protected:
  263. LONG m_cRef;
  264. };
  265. ///////////////////////////////////////////////////////////
  266. //
  267. // Class factory body
  268. //
  269. HRESULT __stdcall IOemCF::QueryInterface(const IID& iid, void** ppv)
  270. {
  271. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
  272. {
  273. *ppv = static_cast<IOemCF*>(this) ;
  274. }
  275. else
  276. {
  277. *ppv = NULL ;
  278. return E_NOINTERFACE ;
  279. }
  280. reinterpret_cast<IUnknown*>(*ppv)->AddRef() ;
  281. return S_OK ;
  282. }
  283. ULONG __stdcall IOemCF::AddRef()
  284. {
  285. return InterlockedIncrement(&m_cRef) ;
  286. }
  287. ULONG __stdcall IOemCF::Release()
  288. {
  289. ASSERT( 0 != m_cRef);
  290. ULONG cRef = InterlockedDecrement(&m_cRef);
  291. if (0 == cRef)
  292. {
  293. delete this;
  294. }
  295. return cRef;
  296. }
  297. // IClassFactory implementation
  298. HRESULT __stdcall IOemCF::CreateInstance(IUnknown* pUnknownOuter,
  299. const IID& iid,
  300. void** ppv)
  301. {
  302. VERBOSE(DLLTEXT("Class factory:\t\tCreate component.")) ;
  303. // Cannot aggregate.
  304. if (pUnknownOuter != NULL)
  305. {
  306. return CLASS_E_NOAGGREGATION ;
  307. }
  308. // Create component.
  309. IOemCB* pOemCB = new IOemCB ;
  310. if (pOemCB == NULL)
  311. {
  312. return E_OUTOFMEMORY ;
  313. }
  314. // Get the requested interface.
  315. HRESULT hr = pOemCB->QueryInterface(iid, ppv) ;
  316. // Release the IUnknown pointer.
  317. // (If QueryInterface failed, component will delete itself.)
  318. pOemCB->Release() ;
  319. return hr ;
  320. }
  321. // LockServer
  322. HRESULT __stdcall IOemCF::LockServer(BOOL bLock)
  323. {
  324. if (bLock)
  325. {
  326. InterlockedIncrement(&g_cServerLocks) ;
  327. }
  328. else
  329. {
  330. InterlockedDecrement(&g_cServerLocks) ;
  331. }
  332. return S_OK ;
  333. }
  334. ///////////////////////////////////////////////////////////
  335. //
  336. // Registration functions
  337. // Testing purpose
  338. //
  339. // Can DLL unload now?
  340. //
  341. STDAPI DllCanUnloadNow()
  342. {
  343. if ((g_cComponents == 0) && (g_cServerLocks == 0))
  344. {
  345. return S_OK ;
  346. }
  347. else
  348. {
  349. return S_FALSE ;
  350. }
  351. }
  352. //
  353. // Get class factory
  354. //
  355. STDAPI DllGetClassObject(const CLSID& clsid,
  356. const IID& iid,
  357. void** ppv)
  358. {
  359. // VERBOSE(DLLTEXT("DllGetClassObject:Create class factory.\n"));
  360. // Can we create this component?
  361. if (clsid != CLSID_OEMUI)
  362. {
  363. return CLASS_E_CLASSNOTAVAILABLE ;
  364. }
  365. // Create class factory.
  366. IOemCF* pFontCF = new IOemCF ; // Reference count set to 1
  367. // in constructor
  368. if (pFontCF == NULL)
  369. {
  370. return E_OUTOFMEMORY ;
  371. }
  372. // Get requested interface.
  373. HRESULT hr = pFontCF->QueryInterface(iid, ppv) ;
  374. pFontCF->Release() ;
  375. return hr ;
  376. }