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.

247 lines
6.1 KiB

  1. // oleprn.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f oleprnps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "stdafx.cpp"
  7. #include <strsafe.h>
  8. #include "prnsec.h"
  9. #include "gensph.h"
  10. #include "initguid.h"
  11. #include "comcat.h"
  12. #include "objsafe.h"
  13. #include "oleprn.h"
  14. #include "oleprn_i.c"
  15. #include "prturl.h"
  16. #include "olesnmp.h"
  17. #include "asphelp.h"
  18. #include "DSPrintQ.h"
  19. #include "OleCvt.h"
  20. #include "oleInst.h"
  21. CComModule _Module;
  22. BEGIN_OBJECT_MAP(ObjectMap)
  23. OBJECT_ENTRY(CLSID_prturl, Cprturl)
  24. OBJECT_ENTRY(CLSID_SNMP, CSNMP)
  25. OBJECT_ENTRY(CLSID_asphelp, Casphelp)
  26. OBJECT_ENTRY(CLSID_DSPrintQueue, CDSPrintQueue)
  27. OBJECT_ENTRY(CLSID_OleCvt, COleCvt)
  28. OBJECT_ENTRY(CLSID_OleInstall, COleInstall)
  29. END_OBJECT_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // DLL Entry Point
  32. extern "C"
  33. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  34. {
  35. BOOL bRet = TRUE;
  36. if (dwReason == DLL_PROCESS_ATTACH) {
  37. _Module.Init(ObjectMap, hInstance);
  38. DisableThreadLibraryCalls(hInstance);
  39. bRet = COlePrnSecurity::InitStrings();
  40. }
  41. else if (dwReason == DLL_PROCESS_DETACH) {
  42. _Module.Term();
  43. COlePrnSecurity::DeallocStrings();
  44. }
  45. return bRet;
  46. }
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Used to determine whether the DLL can be unloaded by OLE
  49. STDAPI DllCanUnloadNow(void)
  50. {
  51. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  52. }
  53. /////////////////////////////////////////////////////////////////////////////
  54. // Returns a class factory to create an object of the requested type
  55. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  56. {
  57. return _Module.GetClassObject(rclsid, riid, ppv);
  58. }
  59. HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
  60. {
  61. ICatRegister* pcr = NULL ;
  62. HRESULT hr = S_OK ;
  63. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  64. NULL,
  65. CLSCTX_INPROC_SERVER,
  66. IID_ICatRegister,
  67. (void**)&pcr);
  68. if (FAILED(hr))
  69. return hr; // Make sure the HKCR\Component Categories\{..catid...}
  70. // key is registered
  71. CATEGORYINFO catinfo;
  72. catinfo.catid = catid;
  73. catinfo.lcid = 0x0409 ; // english
  74. // Make sure the provided description is not too long.
  75. // Only copy the first 127 characters if it is
  76. int len = wcslen(catDescription);
  77. if (len>127)
  78. len = 127;
  79. wcsncpy(catinfo.szDescription, catDescription, len);
  80. // Make sure the description is null terminated
  81. catinfo.szDescription[len] = '\0';
  82. hr = pcr->RegisterCategories(1, &catinfo);
  83. pcr->Release();
  84. return hr;
  85. }
  86. HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  87. {
  88. // Register your component categories information.
  89. ICatRegister* pcr = NULL ;
  90. HRESULT hr = S_OK ;
  91. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  92. NULL,
  93. CLSCTX_INPROC_SERVER,
  94. IID_ICatRegister,
  95. (void**)&pcr);
  96. if (SUCCEEDED(hr)) {
  97. // Register this category as being "implemented" by
  98. // the class.
  99. CATID rgcatid[1] ;
  100. rgcatid[0] = catid;
  101. hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
  102. }
  103. if (pcr != NULL)
  104. pcr->Release();
  105. return hr;
  106. }
  107. HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  108. {
  109. ICatRegister* pcr = NULL ;
  110. HRESULT hr = S_OK ;
  111. hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  112. NULL,
  113. CLSCTX_INPROC_SERVER,
  114. IID_ICatRegister,
  115. (void**)&pcr);
  116. if (SUCCEEDED(hr)) {
  117. // Unregister this category as being "implemented" by
  118. // the class.
  119. CATID rgcatid[1] ;
  120. rgcatid[0] = catid;
  121. hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
  122. }
  123. if (pcr != NULL)
  124. pcr->Release();
  125. return hr;
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. // DllRegisterServer - Adds entries to the system registry
  129. STDAPI DllRegisterServer(void)
  130. {
  131. // Mark as safe for scripting failure OK.
  132. HRESULT hr;
  133. // registers object, typelib and all interfaces in typelib
  134. hr = _Module.RegisterServer(TRUE);
  135. if (FAILED(hr)) return hr;
  136. // After we successfully register it, add the "safe* for scripting" feature
  137. hr = CreateComponentCategory(CATID_SafeForScripting,
  138. L"Controls that are safely scriptable");
  139. if (SUCCEEDED(hr)) {
  140. RegisterCLSIDInCategory(CLSID_prturl, CATID_SafeForScripting);
  141. }
  142. hr = CreateComponentCategory(CATID_SafeForInitializing,
  143. L"Controls safely initializable from persistent data");
  144. if (SUCCEEDED(hr)) {
  145. RegisterCLSIDInCategory(CLSID_prturl, CATID_SafeForInitializing);
  146. }
  147. return hr;
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. // DllUnregisterServer - Removes entries from the system registry
  151. STDAPI DllUnregisterServer(void)
  152. {
  153. UnRegisterCLSIDInCategory (CLSID_prturl, CATID_SafeForScripting);
  154. UnRegisterCLSIDInCategory (CLSID_prturl, CATID_SafeForInitializing);
  155. _Module.UnregisterServer();
  156. return S_OK;
  157. }
  158. /*****************************************************************************\
  159. *
  160. * These function are for linking with spllib.
  161. *
  162. \*****************************************************************************/
  163. EXTERN_C
  164. LPVOID
  165. DllAllocSplMem(
  166. DWORD cb
  167. )
  168. {
  169. return LocalAlloc(LPTR, cb);
  170. }
  171. EXTERN_C
  172. BOOL
  173. DllFreeSplMem(
  174. LPVOID pMem
  175. )
  176. {
  177. LocalFree(pMem);
  178. return TRUE;
  179. }
  180. EXTERN_C
  181. BOOL
  182. DllFreeSplStr(
  183. LPWSTR lpStr
  184. )
  185. {
  186. LocalFree(lpStr);
  187. return TRUE;
  188. }