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.

845 lines
23 KiB

  1. //////////////////////////////////////////////////////////////////
  2. // File : cpadsvrs.cpp
  3. // Purpose : CImePadServer for Shared Memory version.
  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. #ifndef WIN32_LEAN_AND_MEAN
  12. #define WIN32_LEAN_AND_MEAN
  13. #endif
  14. #include <windows.h>
  15. #ifdef UNDER_CE // stub for CE
  16. #include "stub_ce.h"
  17. #endif // UNDER_CE
  18. #include "imepadsv.h"
  19. #include "cpadsvrs.h"
  20. #include "cpadcb.h"
  21. #include "cpaddbg.h"
  22. #include "iimecb.h"
  23. #include "ipoint1.h"
  24. // Safe String
  25. #define STRSAFE_NO_DEPRECATE
  26. #include "strsafe.h"
  27. //----------------------------------------------------------------
  28. //misc definition
  29. //----------------------------------------------------------------
  30. #define Unref(a) UNREFERENCED_PARAMETER(a)
  31. //990812:ToshiaK For Win64. Use Global Alloc/Free Ptr.
  32. #include <windowsx.h>
  33. #define MemAlloc(a) GlobalAllocPtr(GMEM_FIXED, a)
  34. #define MemFree(a) GlobalFreePtr(a)
  35. inline LPVOID
  36. WinSetUserPtr(HWND hwnd, LPVOID lpVoid)
  37. {
  38. #ifdef _WIN64
  39. return (LPVOID)SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lpVoid);
  40. #else
  41. return (LPVOID)SetWindowLong(hwnd, GWL_USERDATA, (LONG)lpVoid);
  42. #endif
  43. }
  44. inline LPVOID
  45. WinGetUserPtr(HWND hwnd)
  46. {
  47. #ifdef _WIN64
  48. return (LPVOID)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  49. #else
  50. return (LPVOID)GetWindowLong(hwnd, GWL_USERDATA);
  51. #endif
  52. }
  53. static LPWSTR
  54. StrdupW(LPWSTR lpwstr)
  55. {
  56. LPWSTR lpwstrRet;
  57. if(!lpwstr) {
  58. return NULL;
  59. }
  60. INT len = lstrlenW(lpwstr);
  61. if(len == 0) {
  62. return NULL;
  63. }
  64. lpwstrRet = (LPWSTR)MemAlloc((len+1) * sizeof(WCHAR));
  65. if(!lpwstrRet) {
  66. return NULL;
  67. }
  68. CopyMemory(lpwstrRet, lpwstr, sizeof(WCHAR)*len);
  69. lpwstrRet[len] = (WCHAR)0x0000;
  70. return lpwstrRet;
  71. }
  72. //----------------------------------------------------------------
  73. //
  74. //public method decalre
  75. //
  76. //----------------------------------------------------------------
  77. //////////////////////////////////////////////////////////////////
  78. // Function : CImePadSvrSharemem::CImePadSvrSharemem
  79. // Type : None
  80. // Purpose : Constructor of CImePadSvrSharemem class
  81. // Args : None
  82. // Return :
  83. // DATE : Mon May 17 23:04:01 1999
  84. // Histroy :
  85. //////////////////////////////////////////////////////////////////
  86. CImePadSvrSharemem::CImePadSvrSharemem(VOID)
  87. {
  88. DBG(("CImePadSvrSharemem::CImePadSvrSharemem() constructor START\n"));
  89. m_imeLangID = 0; //Save Initialized data.
  90. m_dwImeInputID = 0; //Save Initialized data.
  91. m_fShowReqStatus = FALSE; //Save ShowUI()'s bool value.
  92. m_fLastActiveCtx = FALSE; //Save IMEPADNOTIFY_ACTIVATECONTEXT
  93. m_hwndIF = NULL; //Internal I/F Window handle.
  94. m_lpIUnkIImeIPoint = NULL; //IImeIPoint I/F pointer as IUnknown.
  95. m_lpIUnkIImeCallback = NULL; //IImeCallback I/F pointer as IUnknown.
  96. m_lpCImePadCallback = NULL; //CImePadCallback instance pointer.
  97. m_lpIImePadServer = NULL; //IImePadServer I/F pointer.
  98. m_dwRegAdvise = 0;
  99. m_hModuleProxyStub = NULL;
  100. //Initialize Candidate data
  101. ZeroMemory(&m_ntfyDataApplyCand, sizeof(m_ntfyDataApplyCand));
  102. ZeroMemory(&m_ntfyDataQueryCand, sizeof(m_ntfyDataQueryCand));
  103. ZeroMemory(&m_ntfyDataApplyCandEx, sizeof(m_ntfyDataApplyCandEx));
  104. DBG(("CImePadSvrSharemem::CImePadSvrSharemem() constructor END\n"));
  105. }
  106. //////////////////////////////////////////////////////////////////
  107. // Function : CImePadSvrSharemem::~CImePadSvrSharemem
  108. // Type : INT
  109. // Purpose : Destructor of CImePadSvrSharemem Class.
  110. // Args : None
  111. // Return :
  112. // DATE : Mon May 17 23:04:29 1999
  113. // Histroy :
  114. //////////////////////////////////////////////////////////////////
  115. CImePadSvrSharemem::~CImePadSvrSharemem(VOID)
  116. {
  117. DBG(("CImePadSvrSharemem::CImePadSvrSharemem() Destructor START\n"));
  118. this->DestroyIFHWND(TRUE);
  119. m_imeLangID = 0; //Save Initialized data.
  120. m_dwImeInputID = 0; //Save Initialized data.
  121. m_fShowReqStatus = FALSE; //Save ShowUI()'s bool value.
  122. m_fLastActiveCtx = FALSE; //Save IMEPADNOTIFY_ACTIVATECONTEXT
  123. m_hwndIF = NULL; //Internal I/F Window handle.
  124. m_lpIUnkIImeIPoint = NULL; //IImeIPoint I/F pointer as IUnknown.
  125. m_lpIUnkIImeCallback = NULL; //IImeCallback I/F pointer as IUnknown.
  126. m_lpIImePadServer = NULL; //IImePadServer I/F pointer.
  127. //990813:ToshiaK. Memory leak.
  128. if(m_lpCImePadCallback) {
  129. delete m_lpCImePadCallback;
  130. m_lpCImePadCallback = NULL;
  131. }
  132. if(m_hModuleProxyStub) {
  133. ::FreeLibrary(m_hModuleProxyStub);
  134. m_hModuleProxyStub = 0;
  135. }
  136. DBG(("CImePadSvrSharemem::CImePadSvrSharemem() Destructor END\n"));
  137. }
  138. BOOL
  139. CImePadSvrSharemem::IsAvailable(VOID)
  140. {
  141. LPTSTR lpPath = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  142. if(!lpPath) {
  143. DBG(("-->Outof Memory ??\n"));
  144. return FALSE;
  145. }
  146. if(0 == this->CLSID2ModuleName(IID_IImePadServerSHM,
  147. FALSE,
  148. lpPath,
  149. sizeof(TCHAR)*MAX_PATH)) {
  150. MemFree(lpPath);
  151. return TRUE;
  152. }
  153. MemFree(lpPath);
  154. return FALSE;
  155. }
  156. BOOL
  157. CImePadSvrSharemem::OnIMEPadClose(VOID)
  158. {
  159. m_fShowReqStatus = FALSE;
  160. return 0;
  161. }
  162. INT
  163. CImePadSvrSharemem::Initialize(LANGID imeLangID,
  164. DWORD dwImeInputID,
  165. LPVOID lpVoid)
  166. {
  167. DBG(("CImePadSvrSharemem::Initialize() START\n"));
  168. DBG(("--> imeLangID [0x%08x]\n", imeLangID));
  169. DBG(("--> dwImeInputID[0x%08x]\n", dwImeInputID));
  170. if(m_lpIImePadServer) {
  171. DBG(("-->Already Initialized\n"));
  172. return 0;
  173. }
  174. HRESULT hr;
  175. this->CreateIFHWND(); //Create internal Interface Window.
  176. m_imeLangID = imeLangID;
  177. m_dwImeInputID = dwImeInputID;
  178. if(!m_lpCImePadCallback) {
  179. m_lpCImePadCallback = new CImePadCallback(m_hwndIF, this);
  180. }
  181. this->InitOleAPI();
  182. m_lpIImePadServer = (IImePadServer *)this->CreateObject();
  183. if(!m_lpIImePadServer) {
  184. return -1;
  185. }
  186. m_lpIImePadServer->Initialize(::GetCurrentProcessId(),
  187. ::GetCurrentThreadId(),
  188. (DWORD)imeLangID,
  189. (DWORD)dwImeInputID,
  190. FALSE, //fUIM;
  191. m_lpCImePadCallback,
  192. NULL,
  193. 0,
  194. 0);
  195. DBG(("CImePadSvrSharemem::Initialize() END\n"));
  196. return 0;
  197. Unref(lpVoid);
  198. Unref(hr);
  199. }
  200. INT
  201. CImePadSvrSharemem::Terminate(LPVOID lpVoid)
  202. {
  203. DBG(("CImePadSvrSharemem::::Terminate() START \n"));
  204. if(!m_lpIImePadServer) {
  205. return -1;
  206. }
  207. m_lpIImePadServer->Terminate(0, 0);
  208. m_lpIImePadServer = NULL;
  209. //990813:ToshiaK memory leak;
  210. if(m_lpCImePadCallback) {
  211. delete m_lpCImePadCallback;
  212. m_lpCImePadCallback = NULL;
  213. }
  214. DBG(("CImePadSvrSharemem::Terminate() End\n"));
  215. return 0;
  216. Unref(lpVoid);
  217. }
  218. INT
  219. CImePadSvrSharemem::ForceDisConnect(VOID)
  220. {
  221. DBG(("CImePadSvrSharemem::ForceDisConnect START\n"));
  222. if(m_lpIImePadServer) {
  223. m_lpIImePadServer = NULL;
  224. }
  225. DBG(("CImePadSvrSharemem::ForceDisConnect END\n"));
  226. return 0;
  227. }
  228. INT
  229. CImePadSvrSharemem::ShowUI(BOOL fShow)
  230. {
  231. DBG(("CImePadSvrSharemem::ShowUI() START fShow [%d]\n"));
  232. m_fShowReqStatus = fShow;
  233. if(!m_lpIImePadServer) {
  234. return -1;
  235. }
  236. m_lpIImePadServer->ShowUI(fShow);
  237. DBG(("CImePadSvrSharemem::ShowUI() END\n"));
  238. return 0;
  239. }
  240. INT
  241. CImePadSvrSharemem::IsVisible(BOOL *pfVisible)
  242. {
  243. if(pfVisible) {
  244. *pfVisible = m_fShowReqStatus;
  245. }
  246. return 0;
  247. }
  248. INT
  249. CImePadSvrSharemem::ActivateApplet(UINT activateID,
  250. DWORD_PTR dwActivateParam,
  251. LPWSTR lpwstr1,
  252. LPWSTR lpwstr2)
  253. {
  254. DBG(("CImePadSvrSharemem::ActivateApplet START\n"));
  255. DBG(("-->activateID [0x%08x][%s]\n",
  256. activateID,
  257. activateID == IMEPADACTID_ACTIVATEBYCATID ? "IMEPADACTID_ACTIVATEBYCATID" :
  258. activateID == IMEPADACTID_ACTIVATEBYIID ? "IMEPADACTID_ACTIVATEBYIID" :
  259. activateID == IMEPADACTID_ACTIVATEBYNAME ? "IMEPADACTID_ACTIVATEBYNAME" :
  260. "Unknown"));
  261. DBG(("-->dwActivateParam [0x%08x]\n", dwActivateParam));
  262. DBG(("-->lpwstr1 [0x%08x]\n", lpwstr1));
  263. DBG(("-->lpwstr2 [0x%08x]\n", lpwstr2));
  264. if(!m_lpIImePadServer) {
  265. DBG(("-->m_lpIImePadServer is NULL\n"));
  266. DBG(("CImePadSvrSharemem::ActivateApplet END\n"));
  267. return -1;
  268. }
  269. m_lpIImePadServer->ActivateApplet(activateID,
  270. dwActivateParam,
  271. lpwstr1,
  272. lpwstr2);
  273. DBG(("CImePadSvrSharemem::ActivateApplet END\n"));
  274. return 0;
  275. Unref(activateID);
  276. Unref(dwActivateParam);
  277. Unref(lpwstr1);
  278. Unref(lpwstr2);
  279. }
  280. INT
  281. CImePadSvrSharemem::Notify(INT id, WPARAM wParam, LPARAM lParam)
  282. {
  283. HRESULT hr;
  284. switch(id) {
  285. case IMEPADNOTIFY_ACTIVATECONTEXT:
  286. DBG(("CImePadSvrSharemem::Notify: ActivateContext\n"));
  287. //990608:KOTAE #1121. if ImePad is not shown in this application,
  288. //Do not send IMEPADNOTIFY_ACTIVATECONTEXT
  289. if(!m_fShowReqStatus) {
  290. return 0;
  291. }
  292. m_fLastActiveCtx = (BOOL)wParam;
  293. ::KillTimer(m_hwndIF, TIMERID_NOTIFY_ACTIVATECONTEXT);
  294. if(m_fLastActiveCtx) {
  295. ::SetTimer(m_hwndIF,
  296. TIMERID_NOTIFY_ACTIVATECONTEXT,
  297. TIMERELAPS_ACTIVATE,
  298. NULL);
  299. }
  300. else {
  301. ::SetTimer(m_hwndIF,
  302. TIMERID_NOTIFY_ACTIVATECONTEXT,
  303. TIMERELAPS_INACTIVATE,
  304. NULL);
  305. }
  306. break;
  307. case IMEPADNOTIFY_APPLYCANDIDATE:
  308. //----------------------------------------------------------------
  309. // Notify for Candidate Applied
  310. // WPARAM wParam: dwCharId = (DWORD)wParam;
  311. // LPARAM lParam: iSelIndex = (INT)lParam;
  312. //----------------------------------------------------------------
  313. ::KillTimer(m_hwndIF, TIMERID_NOTIFY_APPLYCANDIDATE);
  314. m_ntfyDataApplyCand.dwCharID = (DWORD)wParam;
  315. m_ntfyDataApplyCand.dwSelIndex = (DWORD)lParam;
  316. ::SetTimer(m_hwndIF, TIMERID_NOTIFY_APPLYCANDIDATE, TIMERELAPS_NOTIFY, NULL);
  317. break;
  318. case IMEPADNOTIFY_QUERYCANDIDATE:
  319. //----------------------------------------------------------------
  320. // Notify for Querying Candidate
  321. // WPARAM wParam: dwCharId = (DWORD)wParam;
  322. // LPARAM lParam: 0. not used.
  323. //----------------------------------------------------------------
  324. ::KillTimer(m_hwndIF, TIMERID_NOTIFY_QUERYCANDIDATE);
  325. m_ntfyDataQueryCand.dwCharID = (DWORD)wParam;
  326. ::SetTimer(m_hwndIF, TIMERID_NOTIFY_QUERYCANDIDATE, TIMERELAPS_NOTIFY, NULL);
  327. break;
  328. case IMEPADNOTIFY_APPLYCANDIDATE_EX:
  329. //----------------------------------------------------------------
  330. // Notify for Candidate Applied
  331. // WPARAM wParam: dwCharId = (DWORD)wParam;
  332. // LPARAM lParam: lpApplyCandEx = (LPIMEPADAPPLYCANDEX)lParam;
  333. //----------------------------------------------------------------
  334. {
  335. ::KillTimer(m_hwndIF, TIMERID_NOTIFY_APPLYCANDIDATEEX);
  336. m_ntfyDataApplyCandEx.dwCharID = (DWORD)wParam;
  337. LPIMEPADAPPLYCANDINFO lpApplyCandInfo = (LPIMEPADAPPLYCANDINFO)lParam;
  338. if(m_ntfyDataApplyCandEx.lpwstrCreated1) {
  339. MemFree(m_ntfyDataApplyCandEx.lpwstrCreated1);
  340. }
  341. if(m_ntfyDataApplyCandEx.lpwstrCreated2) {
  342. MemFree(m_ntfyDataApplyCandEx.lpwstrCreated2);
  343. }
  344. m_ntfyDataApplyCandEx.lpwstrCreated1 = NULL;
  345. m_ntfyDataApplyCandEx.lpwstrCreated2 = NULL;
  346. if(lpApplyCandInfo) {
  347. if(lpApplyCandInfo->lpwstrDisplay) {
  348. m_ntfyDataApplyCandEx.lpwstrCreated1 = StrdupW(lpApplyCandInfo->lpwstrDisplay);
  349. }
  350. if(lpApplyCandInfo->lpwstrReading) {
  351. m_ntfyDataApplyCandEx.lpwstrCreated2 = StrdupW(lpApplyCandInfo->lpwstrReading);
  352. }
  353. }
  354. ::SetTimer(m_hwndIF, TIMERID_NOTIFY_APPLYCANDIDATEEX, TIMERELAPS_NOTIFY, NULL);
  355. }
  356. break;
  357. case IMEPADNOTIFY_MODECHANGED:
  358. break;
  359. case IMEPADNOTIFY_STARTCOMPOSITION:
  360. break;
  361. case IMEPADNOTIFY_COMPOSITION:
  362. break;
  363. case IMEPADNOTIFY_ENDCOMPOSITION:
  364. break;
  365. case IMEPADNOTIFY_OPENCANDIDATE:
  366. break;
  367. case IMEPADNOTIFY_CLOSECANDIDATE:
  368. break;
  369. default:
  370. break;
  371. }
  372. return 0;
  373. Unref(hr);
  374. Unref(wParam);
  375. Unref(lParam);
  376. }
  377. INT
  378. CImePadSvrSharemem::GetAppletConfigList(DWORD dwMask,
  379. INT *pCountApplet,
  380. IMEPADAPPLETCONFIG **ppList)
  381. {
  382. DBG(("CImePadSvrSharemem::GetAppletConfigList START\n"));
  383. if(!m_lpIImePadServer) {
  384. DBG(("-->m_lpIImePadServer is NULL\n"));
  385. return -1;
  386. }
  387. HRESULT hr;
  388. hr = m_lpIImePadServer->GetAppletConfigList(dwMask,
  389. (UINT *)pCountApplet,
  390. ppList);
  391. DBG(("CImePadSvrSharemem::GetAppletConfigList END\n"));
  392. return hr;
  393. }
  394. IUnknown *
  395. CImePadSvrSharemem::SetIUnkIImeIPoint(IUnknown *pIUnkIImeIPoint)
  396. {
  397. return m_lpIUnkIImeIPoint = pIUnkIImeIPoint;
  398. }
  399. IUnknown *
  400. CImePadSvrSharemem::SetIUnkIImeCallback(IUnknown *pIUnkIImeCallback)
  401. {
  402. return m_lpIUnkIImeCallback = pIUnkIImeCallback;
  403. }
  404. IUnknown*
  405. CImePadSvrSharemem::GetIUnkIImeIPoint(VOID)
  406. {
  407. return m_lpIUnkIImeIPoint;
  408. }
  409. IUnknown*
  410. CImePadSvrSharemem::GetIUnkIImeCallback(VOID)
  411. {
  412. return m_lpIUnkIImeCallback;
  413. }
  414. //----------------------------------------------------------------
  415. //
  416. //private static method
  417. //
  418. //----------------------------------------------------------------
  419. IImePadServer*
  420. CImePadSvrSharemem::CreateObject(VOID)
  421. {
  422. DBG(("CImePadSvrSharemem::CreateObject START\n"));
  423. typedef LPVOID (WINAPI * LPFN_CREATEOBJECT)(DWORD dwIntanceID);
  424. if(m_hModuleProxyStub) {
  425. DBG(("-->Already Created\n"));
  426. return m_lpIImePadServer;
  427. }
  428. LPTSTR lpPath = (LPTSTR)MemAlloc(sizeof(TCHAR)*MAX_PATH);
  429. if(!lpPath) {
  430. DBG(("-->Outof Memory ??\n"));
  431. return NULL;
  432. }
  433. if(0 != this->CLSID2ModuleName(IID_IImePadServerSHM,
  434. FALSE,
  435. lpPath,
  436. sizeof(TCHAR)*MAX_PATH)) {
  437. DBG(("-->Cannot found proxy\n"));
  438. goto LError;
  439. }
  440. m_hModuleProxyStub= ::LoadLibrary(lpPath);
  441. DBG(("-->lpPath [%s]\n", lpPath));
  442. #if 0
  443. #ifdef _DEBUG
  444. m_hModuleProxyStub = ::LoadLibrary(TEXT("dbgpadsm.dll"));
  445. #else
  446. m_hModuleProxyStub = ::LoadLibrary(TEXT("imepadsm.dll"));
  447. #endif
  448. #endif
  449. if(!m_hModuleProxyStub) {
  450. goto LError;
  451. }
  452. LPFN_CREATEOBJECT lpfn;
  453. lpfn = (LPFN_CREATEOBJECT)::GetProcAddress(m_hModuleProxyStub, "CreateObject");
  454. if(!lpfn) {
  455. DBG(("-->GetProcAddress Error \n"));
  456. goto LError;
  457. }
  458. m_lpIImePadServer = (IImePadServer *)(*lpfn)(0);
  459. return m_lpIImePadServer;
  460. LError:
  461. if(lpPath) {
  462. MemFree(lpPath);
  463. }
  464. return NULL;
  465. }
  466. LRESULT CALLBACK
  467. CImePadSvrSharemem::ClientWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  468. {
  469. LPCImePadSvrSharemem lpCImePadSvr = NULL;
  470. switch(uMsg) {
  471. #ifdef UNDER_CE
  472. case WM_CREATE:
  473. lpCImePadSvr = (LPCImePadSvrSharemem)((LPCREATESTRUCT)lParam)->lpCreateParams;
  474. WinSetUserPtr(hwnd, (LPVOID)lpCImePadSvr);
  475. if(lpCImePadSvr) {
  476. return lpCImePadSvr->RealWndProc(hwnd, uMsg, wParam, lParam);
  477. }
  478. break;
  479. case WM_DESTROY:
  480. lpCImePadSvr = (LPCImePadSvrSharemem)WinGetUserPtr(hwnd);
  481. if(lpCImePadSvr) {
  482. lpCImePadSvr->RealWndProc(hwnd, uMsg, wParam, lParam);
  483. }
  484. WinSetUserPtr(hwnd, (LPVOID)NULL);
  485. break;
  486. #else //!UNDER_CE
  487. case WM_NCCREATE:
  488. lpCImePadSvr = (LPCImePadSvrSharemem)((LPCREATESTRUCT)lParam)->lpCreateParams;
  489. WinSetUserPtr(hwnd, (LPVOID)lpCImePadSvr);
  490. break;
  491. case WM_NCDESTROY:
  492. WinSetUserPtr(hwnd, (LPVOID)NULL);
  493. break;
  494. #endif //UNDER_CE
  495. default:
  496. lpCImePadSvr = (LPCImePadSvrSharemem)WinGetUserPtr(hwnd);
  497. if(lpCImePadSvr) {
  498. return lpCImePadSvr->RealWndProc(hwnd, uMsg, wParam, lParam);
  499. }
  500. break;
  501. }
  502. return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
  503. }
  504. LRESULT
  505. CImePadSvrSharemem::RealWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  506. {
  507. switch(uMsg) {
  508. case WM_CREATE:
  509. DBG(("CImePadSvrSharemem::WM_CREATE\n"));
  510. return 1;
  511. case WM_TIMER:
  512. return MsgTimer(hwnd, wParam, lParam);
  513. case WM_USER_UPDATECONTEXT:
  514. {
  515. IImeIPoint1 *lpIImeIPoint = NULL;
  516. if(!m_lpIUnkIImeIPoint) {
  517. DBG(("--> m_lpIUnkIImeIPoint is NULL\n"));
  518. return E_FAIL;
  519. }
  520. if(IsBadVtbl((IUnkDummy *)m_lpIUnkIImeIPoint)) {
  521. return E_FAIL;
  522. }
  523. HRESULT hr = m_lpIUnkIImeIPoint->QueryInterface(IID_IImeIPoint1,
  524. (VOID **)&lpIImeIPoint);
  525. if(hr != S_OK) {
  526. DBG(("QuertyInterface Failed\n"));
  527. return E_FAIL;
  528. }
  529. if(!lpIImeIPoint) {
  530. DBG(("lpIImeIPoint is NULL\n"));
  531. return 0;
  532. }
  533. //Check current IImeIPoint is same with lParam's IImeIPoint.
  534. //990715:Fixed KOTAE #1563.
  535. //In 16bit application wParam's HIWORD is always 0x0000 !!!!!
  536. //So, Use LParam.
  537. if((IImeIPoint1 *)lParam == lpIImeIPoint) {
  538. DBG(("Call UpdateContext\n"));
  539. lpIImeIPoint->UpdateContext(TRUE);
  540. }
  541. else {
  542. DBG(("lpIImeIPoint is different lParam[0x%08x]\n", lParam));
  543. }
  544. lpIImeIPoint->Release();
  545. }
  546. break;
  547. default:
  548. break;
  549. }
  550. return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
  551. }
  552. LRESULT
  553. CImePadSvrSharemem::MsgTimer(HWND hwnd, WPARAM wParam, LPARAM lParam)
  554. {
  555. HRESULT hr;
  556. switch(wParam) {
  557. case TIMERID_NOTIFY_ACTIVATECONTEXT:
  558. ::KillTimer(hwnd, wParam);
  559. if(!m_lpIImePadServer) {
  560. return -1;
  561. }
  562. m_lpIImePadServer->Notify(IMEPADNOTIFY_ACTIVATECONTEXT,
  563. (WPARAM)m_fLastActiveCtx,
  564. (LPARAM)0);
  565. break;
  566. case TIMERID_NOTIFY_APPLYCANDIDATE:
  567. ::KillTimer(hwnd, wParam);
  568. if(!m_lpIImePadServer) {
  569. return -1;
  570. }
  571. m_lpIImePadServer->NotifyWithData(IMEPADNOTIFY_APPLYCANDIDATE,
  572. m_ntfyDataApplyCand.dwCharID,
  573. 0,
  574. 0,
  575. 0);
  576. m_ntfyDataApplyCand.dwCharID = 0;
  577. break;
  578. case TIMERID_NOTIFY_QUERYCANDIDATE:
  579. ::KillTimer(hwnd, wParam);
  580. m_lpIImePadServer->NotifyWithData(IMEPADNOTIFY_QUERYCANDIDATE,
  581. m_ntfyDataQueryCand.dwCharID,
  582. m_ntfyDataQueryCand.dwSelIndex,
  583. 0,
  584. 0);
  585. m_ntfyDataQueryCand.dwCharID = 0;
  586. m_ntfyDataQueryCand.dwSelIndex = 0;
  587. break;
  588. case TIMERID_NOTIFY_APPLYCANDIDATEEX:
  589. ::KillTimer(hwnd, wParam);
  590. m_lpIImePadServer->NotifyWithData(IMEPADNOTIFY_APPLYCANDIDATE_EX,
  591. m_ntfyDataApplyCandEx.dwCharID,
  592. 0,
  593. m_ntfyDataApplyCandEx.lpwstrCreated1,
  594. m_ntfyDataApplyCandEx.lpwstrCreated2);
  595. if(m_ntfyDataApplyCandEx.lpwstrCreated1) {
  596. MemFree(m_ntfyDataApplyCandEx.lpwstrCreated1);
  597. }
  598. if(m_ntfyDataApplyCandEx.lpwstrCreated2) {
  599. MemFree(m_ntfyDataApplyCandEx.lpwstrCreated2);
  600. }
  601. m_ntfyDataApplyCandEx.lpwstrCreated1 = NULL;
  602. m_ntfyDataApplyCandEx.lpwstrCreated2 = NULL;
  603. break;
  604. default:
  605. ::KillTimer(hwnd, wParam);
  606. break;
  607. }
  608. return 0;
  609. Unref(hr);
  610. Unref(hwnd);
  611. Unref(wParam);
  612. Unref(lParam);
  613. }
  614. //////////////////////////////////////////////////////////////////
  615. // Function : CImePadSvrSharemem::CreateIFHWND
  616. // Type : HWND
  617. // Purpose : Create interface size 0 window.
  618. // Args : None
  619. // Return :
  620. // DATE : Mon May 17 23:01:19 1999
  621. // Histroy :
  622. //////////////////////////////////////////////////////////////////
  623. HWND
  624. CImePadSvrSharemem::CreateIFHWND(VOID)
  625. {
  626. DBG(("CImePadSvrSharemem::CreateIFHWND START\n"));
  627. if(m_hwndIF && ::IsWindow(m_hwndIF)) {
  628. return m_hwndIF;
  629. }
  630. ATOM atom;
  631. HWND hwnd;
  632. #ifndef UNDER_CE // No Ex
  633. WNDCLASSEX wc;
  634. #else // UNDER_CE
  635. WNDCLASS wc;
  636. #endif // UNDER_CE
  637. #ifndef UNDER_CE // No Ex
  638. wc.cbSize = sizeof(wc);
  639. #endif // UNDER_CE
  640. wc.style = 0;
  641. wc.lpfnWndProc = (WNDPROC)CImePadSvrSharemem::ClientWndProc;
  642. wc.cbClsExtra = 0;
  643. wc.cbWndExtra = 0;
  644. wc.hInstance = m_ghModClient;
  645. wc.hIcon = (HICON)NULL;
  646. wc.hCursor = (HCURSOR)NULL;
  647. wc.hbrBackground = (HBRUSH)NULL;
  648. wc.lpszMenuName = NULL;
  649. wc.lpszClassName = SZ_IMEPADIFCLASS;
  650. #ifndef UNDER_CE // No Ex
  651. wc.hIconSm = NULL;
  652. atom = ::RegisterClassEx(&wc);
  653. #else // UNDER_CE
  654. atom = ::RegisterClass(&wc);
  655. #endif // UNDER_CE
  656. hwnd = ::CreateWindowEx(0,
  657. SZ_IMEPADIFCLASS,
  658. NULL,
  659. WS_POPUP | WS_DISABLED,
  660. 0,0,0,0,
  661. NULL,
  662. NULL,
  663. m_ghModClient,
  664. (LPVOID)this);
  665. if(!hwnd) {
  666. DBG(("CreateWindowEx Error %d\n", GetLastError()));
  667. }
  668. m_hwndIF = hwnd;
  669. DBG(("CImePadSvrSharemem::CreateIFHWND END\n"));
  670. return hwnd;
  671. }
  672. //////////////////////////////////////////////////////////////////
  673. // Function : CImePadSvrSharemem::DestroyIFHWND
  674. // Type : BOOL
  675. // Purpose : Destroy interface window.
  676. // Args :
  677. // : BOOL fReserved
  678. // Return :
  679. // DATE : Mon May 17 23:02:43 1999
  680. // Histroy :
  681. //////////////////////////////////////////////////////////////////
  682. BOOL
  683. CImePadSvrSharemem::DestroyIFHWND(BOOL fReserved)
  684. {
  685. DBG(("CImePadSvrSharemem::DestroyIFHWND() START\n"));
  686. if(m_hwndIF && ::IsWindow(m_hwndIF)) {
  687. ::DestroyWindow(m_hwndIF);
  688. m_hwndIF = NULL;
  689. }
  690. //Must Unregister class.
  691. BOOL fRet = ::UnregisterClass(SZ_IMEPADIFCLASS, m_ghModClient);
  692. if(!fRet) {
  693. if(::GetLastError() != ERROR_CLASS_DOES_NOT_EXIST) {
  694. DBG(("UnregisterClass Unknown error [%d]\n", GetLastError()));
  695. }
  696. }
  697. DBG(("CImePadSvrSharemem::DestroyIFHWND() END\n"));
  698. return TRUE;
  699. Unref(fReserved);
  700. }
  701. // Security Fix: strsafe.h
  702. // Add 3rd parameter.
  703. INT
  704. CImePadSvrSharemem::CLSID2Str(REFCLSID refclsid, TCHAR *szBuf, size_t cbBuf)
  705. {
  706. // Security Fix: strsafe.h
  707. // Change wsprintf to StringCbPrintf.
  708. StringCbPrintf(szBuf, cbBuf, TEXT("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
  709. refclsid.Data1,
  710. refclsid.Data2,
  711. refclsid.Data3,
  712. refclsid.Data4[0],
  713. refclsid.Data4[1],
  714. refclsid.Data4[2],
  715. refclsid.Data4[3],
  716. refclsid.Data4[4],
  717. refclsid.Data4[5],
  718. refclsid.Data4[6],
  719. refclsid.Data4[7]);
  720. return 0;
  721. }
  722. //////////////////////////////////////////////////////////////////
  723. // Function : CLSID2ModuleName
  724. // Type : INT
  725. // Purpose : Get module path from CLSID. only gets InprocServer32
  726. // : Path.
  727. // Args :
  728. // : REFCLSID refclsid
  729. // : BOOL fLocalSvr;
  730. // : TCHAR szPath
  731. // : INT cbSize
  732. // Return :
  733. // DATE : Thu Apr 16 02:48:05 1998
  734. // Author :
  735. //////////////////////////////////////////////////////////////////
  736. #define MAX_CLSIDNAME 64
  737. INT
  738. CImePadSvrSharemem::CLSID2ModuleName(REFCLSID refclsid, BOOL fLocalSvr, TCHAR *szPath, INT cbSize)
  739. {
  740. //DBG(("CImePadSvrSharemem::CLSID2ModuleName START\n"));
  741. static TCHAR szCLSID[MAX_CLSIDNAME];
  742. static TCHAR szServerKey[256];
  743. // Security Fix: strsafe.h
  744. // Add 3rd parameter.
  745. CLSID2Str(refclsid, szCLSID, sizeof(szCLSID));
  746. DBG(("-->szCLSID [%s]\n", szCLSID));
  747. // Security Fix: strsafe.h
  748. // Change wsprintf to StringCbPrintf.
  749. if(fLocalSvr) {
  750. StringCbPrintf(szServerKey, sizeof(szServerKey), TEXT("CLSID\\%s\\LocalServer32"), szCLSID);
  751. }
  752. else {
  753. StringCbPrintf(szServerKey, sizeof(szServerKey), TEXT("CLSID\\%s\\InprocServer32"), szCLSID);
  754. }
  755. DBG(("-->szServerKey[%s]\n", szServerKey));
  756. INT ret;
  757. HKEY hKey;
  758. ret = ::RegOpenKeyEx(HKEY_CLASSES_ROOT,
  759. szServerKey,
  760. 0,
  761. KEY_READ, //ALL_ACCESS,
  762. &hKey);
  763. if(ret != ERROR_SUCCESS) {
  764. DBG(("-->RegOpenKeyEx Failed ret=[0x%08x], GLE [0x%08x]\n", ret, GetLastError()));
  765. return ret;
  766. }
  767. ULONG size = cbSize;
  768. ret = ::RegQueryValueEx(hKey,
  769. NULL,
  770. NULL,
  771. NULL,
  772. (LPBYTE)szPath, &size);
  773. if(ret != ERROR_SUCCESS) {
  774. DBG(("-->RegQueryValueEx Failed\n", ret));
  775. ::RegCloseKey(hKey);
  776. return ret;
  777. }
  778. ::RegCloseKey(hKey);
  779. return 0;
  780. }