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.

123 lines
3.5 KiB

  1. //
  2. // regimx.cpp
  3. //
  4. #include "private.h"
  5. #include "regimx.h"
  6. #include "xstring.h"
  7. #include "catutil.h"
  8. #include "msctfp.h"
  9. //+---------------------------------------------------------------------------
  10. //
  11. // RegisterTIP
  12. //
  13. //----------------------------------------------------------------------------
  14. BOOL RegisterTIP(HINSTANCE hInst, REFCLSID rclsid, WCHAR *pwszDesc, const REGTIPLANGPROFILE *plp)
  15. {
  16. ITfInputProcessorProfiles *pReg = NULL;
  17. ITfInputProcessorProfilesEx *pRegEx = NULL;
  18. HRESULT hr;
  19. // register ourselves with the ActiveIMM
  20. hr = CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL,
  21. CLSCTX_INPROC_SERVER,
  22. IID_ITfInputProcessorProfiles, (void**)&pReg);
  23. if (FAILED(hr))
  24. goto Exit;
  25. hr = pReg->Register(rclsid);
  26. if (FAILED(hr))
  27. goto Exit;
  28. pReg->QueryInterface(IID_ITfInputProcessorProfilesEx, (void**)&pRegEx);
  29. while (plp->langid)
  30. {
  31. WCHAR wszFilePath[MAX_PATH];
  32. WCHAR *pv = &wszFilePath[0];
  33. wszFilePath[0] = L'\0';
  34. if (wcslen(plp->szIconFile))
  35. {
  36. char szFilePath[MAX_PATH];
  37. WCHAR *pvCur;
  38. if (0 !=
  39. GetModuleFileName(hInst, szFilePath, ARRAYSIZE(szFilePath)))
  40. {
  41. StringCchCopyW(wszFilePath, ARRAYSIZE(wszFilePath), AtoW(szFilePath));
  42. }
  43. pv = pvCur = &wszFilePath[0];
  44. while (*pvCur)
  45. {
  46. if (*pvCur == L'\\')
  47. pv = pvCur + 1;
  48. pvCur++;
  49. }
  50. *pv = L'\0';
  51. }
  52. UINT uRemainFilePathLen = (ARRAYSIZE(wszFilePath) - (UINT)(pv - &wszFilePath[0] + 1));
  53. StringCchCopyW(pv, uRemainFilePathLen, plp->szIconFile);
  54. pReg->AddLanguageProfile(rclsid,
  55. plp->langid,
  56. *plp->pguidProfile,
  57. plp->szProfile,
  58. wcslen(plp->szProfile),
  59. wszFilePath,
  60. wcslen(wszFilePath),
  61. plp->uIconIndex);
  62. if (pRegEx && plp->uDisplayDescResIndex)
  63. {
  64. pRegEx->SetLanguageProfileDisplayName(rclsid,
  65. plp->langid,
  66. *plp->pguidProfile,
  67. wszFilePath,
  68. wcslen(wszFilePath),
  69. plp->uDisplayDescResIndex);
  70. }
  71. plp++;
  72. }
  73. RegisterGUIDDescription(rclsid, rclsid, pwszDesc);
  74. Exit:
  75. SafeRelease(pReg);
  76. SafeRelease(pRegEx);
  77. return SUCCEEDED(hr);
  78. }
  79. //+---------------------------------------------------------------------------
  80. //
  81. // UnregisterTIP
  82. //
  83. //----------------------------------------------------------------------------
  84. BOOL UnregisterTIP(REFCLSID rclsid)
  85. {
  86. ITfInputProcessorProfiles *pReg;
  87. HRESULT hr;
  88. UnregisterGUIDDescription(rclsid, rclsid);
  89. hr = CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL,
  90. CLSCTX_INPROC_SERVER,
  91. IID_ITfInputProcessorProfiles, (void**)&pReg);
  92. if (FAILED(hr))
  93. goto Exit;
  94. hr = pReg->Unregister(rclsid);
  95. pReg->Release();
  96. Exit:
  97. return FAILED(hr) ? FALSE : TRUE;
  98. }