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.

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