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.

272 lines
6.9 KiB

  1. //==============================================================;
  2. //
  3. // This source code is only intended as a supplement to existing Microsoft documentation.
  4. //
  5. //
  6. //
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  9. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  10. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  11. // PURPOSE.
  12. //
  13. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  14. //
  15. //
  16. //
  17. //==============================================================;
  18. #include <objbase.h>
  19. #include <olectl.h>
  20. #include <initguid.h>
  21. #include "guids.h"
  22. #include "basesnap.h"
  23. #include "Comp.h"
  24. #include "CompData.h"
  25. #include "About.h"
  26. #include "Registry.h"
  27. #include "Extend.h"
  28. // our globals
  29. HINSTANCE g_hinst;
  30. // list all nodes that are extendable here
  31. // List the GUID and then the description
  32. // terminate with a NULL, NULL set.
  33. NODESTRUCT g_Nodes[] = {
  34. { 0xc094012c, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9},
  35. _T("Snap-in Static Node")},
  36. { 0x96713509, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9} ,
  37. _T("People-powered Vehicles Scope Item")},
  38. { 0x9671350a, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9},
  39. _T("Bicyles Scope Item")},
  40. { 0x9671350b, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9} ,
  41. _T("Skate Boards Scope Item")},
  42. { 0x9e3ff365, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9} ,
  43. _T("Ice Skates Scope Item")},
  44. { 0x9e3ff366, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9},
  45. _T("Bicyle Result Item")},
  46. { 0xa6707e01, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9},
  47. _T("Skateboard Result Item")},
  48. { 0xa6707e02, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9} ,
  49. _T("IceSkate Result Item")},
  50. { 0x8512760b, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9},
  51. _T("Land-based Vehicles Scope Item")},
  52. { 0xb17867b9, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9},
  53. _T("Sky-based Vehicles Scope Item")},
  54. { 0xb95e11f4, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9},
  55. _T("Future Vehicles Scope Item")},
  56. { 0xb95e11f5, 0x6be7, 0x11d3, {0x91, 0x56, 0x0, 0xc0, 0x4f, 0x65, 0xb3, 0xf9} ,
  57. _T("Rocket Result Item")},
  58. {NULL, NULL}
  59. };
  60. BOOL WINAPI DllMain(HINSTANCE hinstDLL,
  61. DWORD fdwReason,
  62. void* lpvReserved)
  63. {
  64. if (fdwReason == DLL_PROCESS_ATTACH) {
  65. g_hinst = hinstDLL;
  66. }
  67. return TRUE;
  68. }
  69. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvObj)
  70. {
  71. if ((rclsid != CLSID_CComponentData) && (rclsid != CLSID_CSnapinAbout))
  72. return CLASS_E_CLASSNOTAVAILABLE;
  73. if (!ppvObj)
  74. return E_FAIL;
  75. *ppvObj = NULL;
  76. // We can only hand out IUnknown and IClassFactory pointers. Fail
  77. // if they ask for anything else.
  78. if (!IsEqualIID(riid, IID_IUnknown) && !IsEqualIID(riid, IID_IClassFactory))
  79. return E_NOINTERFACE;
  80. CClassFactory *pFactory = NULL;
  81. // make the factory passing in the creation function for the type of object they want
  82. if (rclsid == CLSID_CComponentData)
  83. pFactory = new CClassFactory(CClassFactory::COMPONENT);
  84. else if (rclsid == CLSID_CSnapinAbout)
  85. pFactory = new CClassFactory(CClassFactory::ABOUT);
  86. if (NULL == pFactory)
  87. return E_OUTOFMEMORY;
  88. HRESULT hr = pFactory->QueryInterface(riid, ppvObj);
  89. return hr;
  90. }
  91. STDAPI DllCanUnloadNow(void)
  92. {
  93. if (g_uObjects == 0 && g_uSrvLock == 0)
  94. return S_OK;
  95. else
  96. return S_FALSE;
  97. }
  98. CClassFactory::CClassFactory(FACTORY_TYPE factoryType)
  99. : m_cref(0), m_factoryType(factoryType)
  100. {
  101. OBJECT_CREATED
  102. }
  103. CClassFactory::~CClassFactory()
  104. {
  105. OBJECT_DESTROYED
  106. }
  107. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, LPVOID *ppv)
  108. {
  109. if (!ppv)
  110. return E_FAIL;
  111. *ppv = NULL;
  112. if (IsEqualIID(riid, IID_IUnknown))
  113. *ppv = static_cast<IClassFactory *>(this);
  114. else
  115. if (IsEqualIID(riid, IID_IClassFactory))
  116. *ppv = static_cast<IClassFactory *>(this);
  117. if (*ppv)
  118. {
  119. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  120. return S_OK;
  121. }
  122. return E_NOINTERFACE;
  123. }
  124. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  125. {
  126. return InterlockedIncrement((LONG *)&m_cref);
  127. }
  128. STDMETHODIMP_(ULONG) CClassFactory::Release()
  129. {
  130. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  131. {
  132. delete this;
  133. return 0;
  134. }
  135. return m_cref;
  136. }
  137. STDMETHODIMP CClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID * ppvObj)
  138. {
  139. HRESULT hr;
  140. void* pObj;
  141. if (!ppvObj)
  142. return E_FAIL;
  143. *ppvObj = NULL;
  144. // Our object does does not support aggregation, so we need to
  145. // fail if they ask us to do aggregation.
  146. if (pUnkOuter)
  147. return CLASS_E_NOAGGREGATION;
  148. if (COMPONENT == m_factoryType) {
  149. pObj = new CComponentData();
  150. } else {
  151. pObj = new CSnapinAbout();
  152. }
  153. if (!pObj)
  154. return E_OUTOFMEMORY;
  155. // QueryInterface will do the AddRef() for us, so we do not
  156. // do it in this function
  157. hr = ((LPUNKNOWN)pObj)->QueryInterface(riid, ppvObj);
  158. if (FAILED(hr))
  159. delete pObj;
  160. return hr;
  161. }
  162. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  163. {
  164. if (fLock)
  165. InterlockedIncrement((LONG *)&g_uSrvLock);
  166. else
  167. InterlockedDecrement((LONG *)&g_uSrvLock);
  168. return S_OK;
  169. }
  170. //////////////////////////////////////////////////////////
  171. //
  172. // Exported functions
  173. //
  174. //
  175. // Server registration
  176. //
  177. STDAPI DllRegisterServer()
  178. {
  179. HRESULT hr = SELFREG_E_CLASS;
  180. _TCHAR szName[256];
  181. _TCHAR szSnapInName[256];
  182. LoadString(g_hinst, IDS_NAME, szName, sizeof(szName));
  183. LoadString(g_hinst, IDS_SNAPINNAME, szSnapInName, sizeof(szSnapInName));
  184. _TCHAR szAboutName[256];
  185. LoadString(g_hinst, IDS_ABOUTNAME, szAboutName, sizeof(szAboutName));
  186. // register our CoClasses
  187. hr = RegisterServer(g_hinst,
  188. CLSID_CComponentData,
  189. szName);
  190. if SUCCEEDED(hr)
  191. hr = RegisterServer(g_hinst,
  192. CLSID_CSnapinAbout,
  193. szAboutName);
  194. // place the registry information for SnapIns
  195. if SUCCEEDED(hr)
  196. hr = RegisterSnapin(CLSID_CComponentData, szSnapInName, CLSID_CSnapinAbout);
  197. return hr;
  198. }
  199. STDAPI DllUnregisterServer()
  200. {
  201. if (UnregisterServer(CLSID_CComponentData) == S_OK)
  202. return UnregisterSnapin(CLSID_CComponentData);
  203. else
  204. return E_FAIL;
  205. }