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.

234 lines
7.3 KiB

  1. //////////////////////////////////////////////////////////////////
  2. // File : cpadsvr.cpp
  3. // Purpose : Client source code for IMEPad executable.
  4. //
  5. //
  6. // Date : Fri Apr 16 15:39:33 1999
  7. // Author : ToshiaK
  8. //
  9. // Copyright(c) 1995-1999, Microsoft Corp. All rights reserved
  10. //////////////////////////////////////////////////////////////////
  11. #include <windows.h>
  12. #include "cpadsvu.h"
  13. #include "cpaddbg.h"
  14. #include "cpadsvus.h" //Use Shared Memory for IPC.
  15. //----------------------------------------------------------------
  16. //misc definition
  17. //----------------------------------------------------------------
  18. #define Unref(a) UNREFERENCED_PARAMETER(a)
  19. //990812:ToshiaK For Win64. Use Global Alloc/Free Ptr.
  20. #include <windowsx.h>
  21. #define MemAlloc(a) GlobalAllocPtr(GMEM_FIXED, a)
  22. #define MemFree(a) GlobalFreePtr(a)
  23. //----------------------------------------------------------------
  24. //OLE function is dynamically loaded/called
  25. //----------------------------------------------------------------
  26. #define SZMOD_OLE32DLL TEXT("OLE32.DLL")
  27. #ifdef UNDER_CE // For GetModuleHandleW
  28. #define WSZMOD_OLE32DLL L"OLE32.DLL"
  29. #endif // UNDER_CE
  30. #define SZFN_COINITIALIZE "CoInitialize"
  31. #define SZFN_COCREATEINSTANCE "CoCreateInstance"
  32. #define SZFN_COUNINITIALIZE "CoUninitialize"
  33. #define SZFN_CODISCONNECTOBJECT "CoDisconnectObject"
  34. #define SZFN_COTASKMEMALLOC "CoTaskMemAlloc"
  35. #define SZFN_COTASKMEMREALLOC "CoTaskMemRealloc"
  36. #define SZFN_COTASKMEMFREE "CoTaskMemFree"
  37. //////////////////////////////////////////////////////////////////
  38. // Function : CImePadSvrUIM::CreateInstance
  39. // Type : HRESULT
  40. // Purpose : Create New CImePadSvrUIM instance.
  41. // Args :
  42. // : LPCImePadSvrUIM * pp
  43. // : LPARAM lReserved1 //not used. must be ZERO.
  44. // : LPARAM lReserved2 //not used. must be ZERO.
  45. // Return :
  46. // DATE : Tue Mar 28 00:31:26 2000
  47. // Histroy :
  48. //////////////////////////////////////////////////////////////////
  49. HRESULT
  50. CImePadSvrUIM::CreateInstance(HINSTANCE hInst,
  51. LPCImePadSvrUIM *pp,
  52. LPARAM lReserved1,
  53. LPARAM lReserved2)
  54. {
  55. if(!pp) {
  56. return S_FALSE;
  57. }
  58. LPCImePadSvrUIM lpCImePadSvrUIM;
  59. lpCImePadSvrUIM = NULL;
  60. lpCImePadSvrUIM = new CImePadSvrUIM_Sharemem(hInst);
  61. if(lpCImePadSvrUIM) {
  62. if(!lpCImePadSvrUIM->IsAvailable()) {
  63. delete lpCImePadSvrUIM;
  64. lpCImePadSvrUIM = NULL;
  65. *pp = NULL;
  66. return S_FALSE;
  67. }
  68. *pp = lpCImePadSvrUIM;
  69. return S_OK;
  70. }
  71. return S_FALSE;
  72. UNREFERENCED_PARAMETER(lReserved1);
  73. UNREFERENCED_PARAMETER(lReserved2);
  74. }
  75. HRESULT
  76. CImePadSvrUIM::DeleteInstance(LPCImePadSvrUIM lpCImePadSvrUIM,
  77. LPARAM lReserved)
  78. {
  79. lReserved; // no ref
  80. DBG(("CImePadSvrUIM::DestroyCImePadSvrUIM START\n"));
  81. if(!lpCImePadSvrUIM) {
  82. return S_FALSE;
  83. }
  84. lpCImePadSvrUIM->Terminate(NULL);
  85. delete lpCImePadSvrUIM;
  86. DBG(("CImePadSvrUIM::DestroyCImePadSvrUIM END\n"));
  87. return S_OK;
  88. }
  89. //////////////////////////////////////////////////////////////////
  90. // Function : CImePadSvrUIM::CImePadSvrUIM
  91. // Type :
  92. // Purpose : Constructor of CImePadSvrUIM
  93. // Args : None
  94. // Return :
  95. // DATE : Mon May 17 23:37:18 1999
  96. // Histroy :
  97. //////////////////////////////////////////////////////////////////
  98. CImePadSvrUIM::CImePadSvrUIM(HINSTANCE hInst)
  99. {
  100. DBG(("CImePadSvrUIM::CImePadSvrUIM START\n"));
  101. m_fCoInitSuccess = FALSE; //Flag for CoInitialize() successed or not.
  102. m_fOLELoaded = FALSE; //OLE32.DLL is loaded by Application or explicitly loaded.
  103. m_hModOLE = FALSE; //OLE32.DLL module handle.
  104. m_fnCoInitialize = NULL; //CoInitialize() function pointer.
  105. m_fnCoCreateInstance = NULL; //CoCreateInstance() function pointer.
  106. m_fnCoUninitialize = NULL; //CoUninitialize() function pointer.
  107. m_fnCoDisconnectObject = NULL; //CoDisconnectObject() function pointer.
  108. m_fnCoTaskMemAlloc = NULL; //CoTaskMemAlloc() function pointer.
  109. m_fnCoTaskMemRealloc = NULL; //CoTaskMemRealloc() function pointer.
  110. m_fnCoTaskMemFree = NULL; //CoTaskMemFree() function pointer.
  111. m_hModClient = (HMODULE)hInst;
  112. DBG(("CImePadSvrUIM::CImePadSvrUIM END\n"));
  113. }
  114. CImePadSvrUIM::~CImePadSvrUIM()
  115. {
  116. DBG(("CImePadSvrUIM::~CImePadSvrUIM START\n"));
  117. m_fCoInitSuccess = FALSE; //Flag for CoInitialize() successed or not.
  118. m_fOLELoaded = FALSE; //OLE32.DLL is loaded by Application or explicitly loaded.
  119. m_hModOLE = FALSE; //OLE32.DLL module handle.
  120. m_fnCoInitialize = NULL; //CoInitialize() function pointer.
  121. m_fnCoCreateInstance = NULL; //CoCreateInstance() function pointer.
  122. m_fnCoUninitialize = NULL; //CoUninitialize() function pointer.
  123. m_fnCoDisconnectObject = NULL; //CoDisconnectObject() function pointer.
  124. m_fnCoTaskMemAlloc = NULL; //CoTaskMemAlloc() function pointer.
  125. m_fnCoTaskMemRealloc = NULL; //CoTaskMemRealloc() function pointer.
  126. m_fnCoTaskMemFree = NULL; //CoTaskMemFree() function pointer.
  127. m_hModClient = NULL;
  128. DBG(("CImePadSvrUIM::~CImePadSvrUIM END\n"));
  129. }
  130. BOOL
  131. CImePadSvrUIM::InitOleAPI(VOID)
  132. {
  133. DBG(("CImePadSvrUIM::InitOleAPI START\n"));
  134. if(!m_hModOLE) {
  135. #ifndef UNDER_CE // For GetModuleHandleW
  136. m_hModOLE = ::GetModuleHandle(SZMOD_OLE32DLL);
  137. #else // UNDER_CE
  138. m_hModOLE = ::GetModuleHandleW(WSZMOD_OLE32DLL);
  139. #endif // UNDER_CE
  140. if(m_hModOLE) {
  141. DBG(("-->%s is Loaded by Application\n", SZMOD_OLE32DLL));
  142. m_fOLELoaded = FALSE;
  143. }
  144. else {
  145. m_hModOLE = ::LoadLibrary(SZMOD_OLE32DLL);
  146. if(m_hModOLE) {
  147. DBG(("--> %s has Loaded Explicitly", SZMOD_OLE32DLL));
  148. m_fOLELoaded = TRUE;
  149. }
  150. else {
  151. return FALSE;
  152. }
  153. }
  154. }
  155. m_fnCoInitialize = (FN_COINITIALIZE) GetProcAddress(m_hModOLE, SZFN_COINITIALIZE);
  156. m_fnCoCreateInstance = (FN_COCREATEINSTANCE) ::GetProcAddress(m_hModOLE, SZFN_COCREATEINSTANCE);
  157. m_fnCoUninitialize = (FN_COUNINITIALIZE) ::GetProcAddress(m_hModOLE, SZFN_COUNINITIALIZE);
  158. m_fnCoDisconnectObject= (FN_CODISCONNECTOBJECT) ::GetProcAddress(m_hModOLE, SZFN_CODISCONNECTOBJECT);
  159. m_fnCoTaskMemAlloc = (FN_COTASKMEMALLOC) ::GetProcAddress(m_hModOLE, SZFN_COTASKMEMALLOC);
  160. m_fnCoTaskMemRealloc = (FN_COTASKMEMREALLOC) ::GetProcAddress(m_hModOLE, SZFN_COTASKMEMREALLOC);
  161. m_fnCoTaskMemFree = (FN_COTASKMEMFREE) ::GetProcAddress(m_hModOLE, SZFN_COTASKMEMFREE);
  162. if(!m_fnCoInitialize ||
  163. !m_fnCoCreateInstance ||
  164. !m_fnCoUninitialize ||
  165. !m_fnCoDisconnectObject ||
  166. !m_fnCoTaskMemAlloc ||
  167. !m_fnCoTaskMemRealloc ||
  168. !m_fnCoTaskMemFree) {
  169. DBG(("InitOleAPI Failed: GetProcAddress Error\n"));
  170. return FALSE;
  171. }
  172. DBG(("CImePadSvrUIM::InitOleAPI END\n"));
  173. return TRUE;
  174. }
  175. BOOL
  176. CImePadSvrUIM::TermOleAPI(VOID)
  177. {
  178. DBG(("CImePadSvrUIM::TermOleAPI START\n"));
  179. m_fnCoInitialize = NULL;
  180. m_fnCoCreateInstance = NULL;
  181. m_fnCoUninitialize = NULL;
  182. m_fnCoDisconnectObject = NULL;
  183. m_fnCoTaskMemAlloc = NULL;
  184. m_fnCoTaskMemRealloc = NULL;
  185. m_fnCoTaskMemFree = NULL;
  186. if(!m_hModOLE) {
  187. DBG(("-->TermOleAPI already Terminated?\n"));
  188. return TRUE;
  189. }
  190. if(m_hModOLE && m_fOLELoaded) {
  191. DBG(("--> FreeLibrary\n"));
  192. ::FreeLibrary(m_hModOLE);
  193. }
  194. m_hModOLE = NULL;
  195. m_fOLELoaded = FALSE;
  196. DBG(("CImePadSvrUIM::TermOleAPI END\n"));
  197. return TRUE;
  198. }
  199. #if 0
  200. VOID*
  201. CImePadSvrUIM::operator new( size_t size )
  202. {
  203. LPVOID lp = (LPVOID)MemAlloc(size);
  204. return lp;
  205. }
  206. VOID
  207. CImePadSvrUIM::operator delete( VOID *lp )
  208. {
  209. if(lp) {
  210. MemFree(lp);
  211. }
  212. return;
  213. }
  214. #endif