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.

291 lines
8.2 KiB

  1. //////////////////////////////////////////////////////////////////
  2. // File : cfactory.cpp
  3. // Purpose : IClassFactory interface implement.
  4. //
  5. //
  6. // Copyright(c) 1995-1998, Microsoft Corp. All rights reserved.
  7. //
  8. //////////////////////////////////////////////////////////////////
  9. #define INITGUID 1
  10. #include <objbase.h>
  11. #include <comcat.h>
  12. #include "cfactory.h"
  13. #include "registry.h"
  14. #include "guids.h"
  15. #include "hwxapp.h"
  16. #include "imepad.h"
  17. #define MSAA
  18. #ifdef MSAA // used by lib(plv etc.)
  19. #include <oleacc.h>
  20. #endif
  21. //////////////////////////////////////////////////////////////////
  22. //
  23. // static member variable declaration.
  24. //
  25. LONG CFactory::m_cServerLocks = 0; // Locked count
  26. LONG CFactory::m_cComponents = 0; // Locked count
  27. HMODULE CFactory::m_hModule = NULL ; // DLL module handle
  28. FACTARRAY CFactory::m_fData = {
  29. &CLSID_ImePadApplet_MultiBox,
  30. #ifndef UNDER_CE
  31. #ifdef FE_JAPANESE
  32. "MS-IME 2000 HandWriting Applet",
  33. #elif FE_KOREAN
  34. "MS Korean IME 6.1 HandWriting Applet",
  35. #else
  36. "MSIME98 HandWriting Applet",
  37. #endif
  38. "IMEPad.HWR",
  39. "IMEPad.HWR.6.1",
  40. #else // UNDER_CE
  41. #ifdef FE_JAPANESE
  42. TEXT("MS-IME 2000 HandWriting Applet"),
  43. #elif FE_KOREAN
  44. "MS Korean IME 6.1 HandWriting Applet",
  45. #else
  46. TEXT("MSIME98 HandWriting Applet"),
  47. #endif
  48. TEXT("IMEPad.HWR"),
  49. TEXT("IMEPad.HWR.8"),
  50. #endif // UNDER_CE
  51. };
  52. //////////////////////////////////////////////////////////////////
  53. //
  54. // static data definition
  55. //////////////////////////////////////////////////////////////////
  56. // Function : CFactory::CFactory
  57. // Type : None
  58. // Purpose : Constructor
  59. // Args : None
  60. // Return :
  61. // DATE : Wed Mar 25 14:38:30 1998
  62. //////////////////////////////////////////////////////////////////
  63. CFactory::CFactory(VOID) : m_cRef(1)
  64. {
  65. }
  66. //////////////////////////////////////////////////////////////////
  67. // Function : CFactory::~CFactory
  68. // Type : None
  69. // Purpose : Destructor
  70. // Args : None
  71. // Return :
  72. // DATE : Wed Mar 25 14:38:30 1998
  73. //////////////////////////////////////////////////////////////////
  74. CFactory::~CFactory(VOID)
  75. {
  76. }
  77. //////////////////////////////////////////////////////////////////
  78. //
  79. // IUnknown implementation
  80. //
  81. //////////////////////////////////////////////////////////////////
  82. // Function : CFactory::QueryInterface
  83. // Type : HRESULT __stdcall
  84. // Purpose :
  85. // Args :
  86. // : REFIID iid
  87. // : LPVOID *ppv;
  88. // Return :
  89. // DATE : Wed Mar 25 14:40:29 1998
  90. //////////////////////////////////////////////////////////////////
  91. HRESULT __stdcall CFactory::QueryInterface(REFIID iid, LPVOID * ppv)
  92. {
  93. IUnknown* pI ;
  94. if ((iid == IID_IUnknown) || (iid == IID_IClassFactory)) {
  95. pI= this ;
  96. }
  97. else {
  98. *ppv = NULL ;
  99. return E_NOINTERFACE ;
  100. }
  101. pI->AddRef() ;
  102. *ppv = pI ;
  103. return S_OK ;
  104. }
  105. //////////////////////////////////////////////////////////////////
  106. // Function : CFactory::AddRef
  107. // Type : ULONG __stdcall
  108. // Purpose :
  109. // Args : None
  110. // Return : reference count
  111. // DATE : Wed Mar 25 15:40:07 1998
  112. //////////////////////////////////////////////////////////////////
  113. ULONG __stdcall CFactory::AddRef()
  114. {
  115. ::InterlockedIncrement(&m_cRef) ;
  116. return (ULONG)m_cRef;
  117. }
  118. //////////////////////////////////////////////////////////////////
  119. // Function : CFactory::Release
  120. // Type : ULONG __stdcall
  121. // Purpose :
  122. // Args : None
  123. // Return : reference count
  124. // DATE : Wed Mar 25 15:40:41 1998
  125. //////////////////////////////////////////////////////////////////
  126. ULONG __stdcall CFactory::Release()
  127. {
  128. if(0 == ::InterlockedDecrement(&m_cRef)) {
  129. delete this;
  130. return 0;
  131. }
  132. return m_cRef ;
  133. }
  134. //////////////////////////////////////////////////////////////////
  135. //
  136. // IClassFactory implementation
  137. //
  138. //////////////////////////////////////////////////////////////////
  139. // Function : CFactory::CreateInstance
  140. // Type : HRESULT __stdcall
  141. // Purpose :
  142. // Args :
  143. // : IUnknown * pUnknownOuter
  144. // : REFIID riid
  145. // : LPVOID * ppv
  146. // Return :
  147. // DATE : Wed Mar 25 15:05:37 1998
  148. //////////////////////////////////////////////////////////////////
  149. HRESULT __stdcall CFactory::CreateInstance(IUnknown* pUnknownOuter,
  150. REFIID refiid,
  151. LPVOID *ppv)
  152. {
  153. // Create the component.
  154. HRESULT hr;
  155. if((pUnknownOuter != NULL) && (refiid != IID_IUnknown)) {
  156. return CLASS_E_NOAGGREGATION ;
  157. }
  158. CApplet *lpCApplet = new CApplet(m_hModule);
  159. if(!lpCApplet) {
  160. return E_OUTOFMEMORY;
  161. }
  162. hr = lpCApplet->QueryInterface(refiid, ppv);
  163. if(FAILED(hr)) {
  164. return hr;
  165. }
  166. lpCApplet->Release();
  167. return hr;
  168. }
  169. //////////////////////////////////////////////////////////////////
  170. // Function : CFactory::LockServer
  171. // Type : HRESULT __stdcall
  172. // Purpose :
  173. // Args :
  174. // : BOOL bLock
  175. // Return :
  176. // DATE : Wed Mar 25 15:13:41 1998
  177. //////////////////////////////////////////////////////////////////
  178. HRESULT __stdcall CFactory::LockServer(BOOL bLock)
  179. {
  180. if (bLock) {
  181. ::InterlockedIncrement(&m_cServerLocks) ;
  182. }
  183. else {
  184. ::InterlockedDecrement(&m_cServerLocks) ;
  185. }
  186. return S_OK ;
  187. }
  188. //////////////////////////////////////////////////////////////////
  189. // Function : CFactory::GetClassObject
  190. // Type : HRESULT
  191. // Purpose : Called from exported API, DllGetClassObject()
  192. // Args :
  193. // : REFCLSID rclsid
  194. // : REFIID iid
  195. // : LPVOID * ppv
  196. // Return :
  197. // DATE : Wed Mar 25 15:37:50 1998
  198. //////////////////////////////////////////////////////////////////
  199. HRESULT CFactory::GetClassObject(REFCLSID rclsid,
  200. REFIID iid,
  201. LPVOID *ppv)
  202. {
  203. if((iid != IID_IUnknown) && (iid != IID_IClassFactory)) {
  204. return E_NOINTERFACE ;
  205. }
  206. if(rclsid == CLSID_ImePadApplet_MultiBox) {
  207. *ppv = (IUnknown *) new CFactory();
  208. if(*ppv == NULL) {
  209. return E_OUTOFMEMORY ;
  210. }
  211. return NOERROR ;
  212. }
  213. return CLASS_E_CLASSNOTAVAILABLE ;
  214. }
  215. //////////////////////////////////////////////////////////////////
  216. // Function : CFactory::RegisterServer
  217. // Type : HRESULT
  218. // Purpose : Called from exported API DllRegisterServer()
  219. // Args : None
  220. // Return :
  221. // DATE : Wed Mar 25 17:03:13 1998
  222. //////////////////////////////////////////////////////////////////
  223. HRESULT CFactory::RegisterServer(VOID)
  224. {
  225. // Get server location.
  226. Register(m_hModule,
  227. *m_fData.lpClsId,
  228. m_fData.lpstrRegistryName,
  229. m_fData.lpstrProgID,
  230. m_fData.lpstrVerIndProfID);
  231. RegisterCategory(TRUE,
  232. CATID_MSIME_IImePadApplet,
  233. CLSID_ImePadApplet_MultiBox);
  234. return S_OK ;
  235. }
  236. //////////////////////////////////////////////////////////////////
  237. // Function : CFactory::UnregisterServer
  238. // Type : HRESULT
  239. // Purpose : Called from exported API, DllUnregisterServer()
  240. // Args : None
  241. // Return :
  242. // DATE : Wed Mar 25 17:02:01 1998
  243. //////////////////////////////////////////////////////////////////
  244. HRESULT CFactory::UnregisterServer(VOID)
  245. {
  246. RegisterCategory(FALSE,
  247. CATID_MSIME_IImePadApplet,
  248. CLSID_ImePadApplet_MultiBox);
  249. Unregister(*m_fData.lpClsId,
  250. m_fData.lpstrVerIndProfID,
  251. m_fData.lpstrProgID);
  252. return S_OK ;
  253. }
  254. //////////////////////////////////////////////////////////////////
  255. // Function : CFactory::CanUnloadNow
  256. // Type : HRESULT
  257. // Purpose : Called from exported API, DllCanUnloadNow()
  258. // Args : None
  259. // Return :
  260. // DATE : Wed Mar 25 17:02:18 1998
  261. //////////////////////////////////////////////////////////////////
  262. HRESULT CFactory::CanUnloadNow()
  263. {
  264. if(IsLocked()) {
  265. return S_FALSE ;
  266. }
  267. else {
  268. return S_OK ;
  269. }
  270. }