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.

224 lines
5.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // File: server.cpp
  4. //
  5. // Contents: COM server functionality.
  6. //
  7. //----------------------------------------------------------------------------
  8. #include "private.h"
  9. #include "globals.h"
  10. #include "sapilayr.h"
  11. #include "regsvr.h"
  12. #include "regimx.h"
  13. #include "status.h"
  14. #include "catutil.h"
  15. #include "cregkey.h"
  16. #include "nui.h"
  17. #include "mui.h"
  18. #include "proppage.h"
  19. #include "immxutil.h"
  20. #ifdef DEBUG
  21. DWORD g_dwThreadDllMain = 0;
  22. #endif
  23. BEGIN_COCLASSFACTORY_TABLE
  24. DECLARE_COCLASSFACTORY_ENTRY(CLSID_SapiLayr, CSapiIMX, TEXT("Cicero SAPI Layer IMX"))
  25. DECLARE_COCLASSFACTORY_ENTRY(CLSID_SpeechUIServer, CSpeechUIServer, TEXT("Cicero SAPI Layer Speech UI Server"))
  26. END_COCLASSFACTORY_TABLE
  27. extern CComModule _Module;
  28. //+---------------------------------------------------------------------------
  29. //
  30. // ProcessAttach
  31. //
  32. //----------------------------------------------------------------------------
  33. BOOL ProcessAttach(HINSTANCE hInstance)
  34. {
  35. CcshellGetDebugFlags();
  36. Dbg_MemInit(TEXT("SPTIP"), NULL);
  37. g_hInst = hInstance;
  38. g_dwTlsIndex = TlsAlloc();
  39. if (!g_cs.Init())
  40. return FALSE;
  41. CSapiIMX::RegisterWorkerClass(hInstance);
  42. MuiLoadResource(hInstance, TEXT("sptip.dll"));
  43. _Module.Init(NULL, hInstance);
  44. return TRUE;
  45. }
  46. //+---------------------------------------------------------------------------
  47. //
  48. // ProcessDettach
  49. //
  50. //----------------------------------------------------------------------------
  51. void ProcessDettach(HINSTANCE hInstance)
  52. {
  53. _Module.Term();
  54. MuiClearResource();
  55. UninitProcess();
  56. g_cs.Delete();
  57. TlsFree(g_dwTlsIndex);
  58. Dbg_MemUninit();
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // DllMain
  63. //
  64. //----------------------------------------------------------------------------
  65. STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID pvReserved)
  66. {
  67. BOOL bRet = TRUE;
  68. #ifdef DEBUG
  69. g_dwThreadDllMain = GetCurrentThreadId();
  70. #endif
  71. switch (dwReason)
  72. {
  73. case DLL_PROCESS_ATTACH:
  74. //
  75. // Now real DllEntry point is _DllMainCRTStartup.
  76. // _DllMainCRTStartup does not call our DllMain(DLL_PROCESS_DETACH)
  77. // if our DllMain(DLL_PROCESS_ATTACH) fails.
  78. // So we have to clean this up.
  79. //
  80. if (!ProcessAttach(hInstance))
  81. {
  82. ProcessDettach(hInstance);
  83. bRet = FALSE;
  84. }
  85. break;
  86. case DLL_THREAD_ATTACH:
  87. break;
  88. case DLL_PROCESS_DETACH:
  89. ProcessDettach(hInstance);
  90. break;
  91. case DLL_THREAD_DETACH:
  92. FreeSPTIPTHREAD();
  93. break;
  94. }
  95. #ifdef DEBUG
  96. g_dwThreadDllMain = 0;
  97. #endif
  98. return bRet;
  99. }
  100. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppvObj)
  101. {
  102. return COMBase_DllGetClassObject(rclsid, riid, ppvObj);
  103. }
  104. STDAPI DllCanUnloadNow(void)
  105. {
  106. return COMBase_DllCanUnloadNow();
  107. }
  108. const REGISTERCAT c_rgRegCat[] =
  109. {
  110. {&GUID_TFCAT_TIP_SPEECH, &CLSID_SapiLayr},
  111. {&GUID_TFCAT_PROPSTYLE_STATIC, &GUID_PROP_SAPI_DISPATTR},
  112. {&GUID_TFCAT_PROPSTYLE_CUSTOM, &GUID_PROP_SAPIRESULTOBJECT},
  113. {&GUID_TFCAT_PROP_AUDIODATA, &GUID_PROP_SAPIRESULTOBJECT},
  114. {&GUID_TFCAT_PROPSTYLE_CUSTOM, &GUID_PROP_LMLATTICE},
  115. {&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_SapiLayr},
  116. {&GUID_TFCAT_DISPLAYATTRIBUTEPROPERTY, &GUID_PROP_SAPI_DISPATTR},
  117. {NULL, NULL}
  118. };
  119. REGTIPLANGPROFILE rgNulProf[] = {
  120. {0x0FFFF, &c_guidProfileBogus, L"Speech Recognition", L"sptip.dll", 0, IDS_DEFAULT_PROFILE},
  121. {0, NULL, L"", L"", 0, 0},
  122. };
  123. STDAPI DllRegisterServer(void)
  124. {
  125. WCHAR szDAP[] = L"SAPI Layer Display Attribute Provider";
  126. WCHAR szDAProp[] = L"SAPI Layer Display Attribute Property";
  127. WCHAR szDefaultProf[128];
  128. HRESULT hr = E_FAIL;
  129. CComPtr<ITfInputProcessorProfiles> cpProfileMgr;
  130. TFInitLib();
  131. if (COMBase_DllRegisterServer() != S_OK)
  132. goto Exit;
  133. if (CicLoadStringWrapW(g_hInst, IDS_DEFAULT_PROFILE, szDefaultProf, ARRAYSIZE(szDefaultProf)))
  134. StringCchCopyW(rgNulProf->szProfile,ARRAYSIZE(rgNulProf->szProfile), szDefaultProf);
  135. if (!RegisterTIP(g_hInst, CLSID_SapiLayr, L"SapiLayer TIP", rgNulProf))
  136. goto Exit;
  137. if (FAILED(RegisterCategories(CLSID_SapiLayr, c_rgRegCat)))
  138. goto Exit;
  139. if (FAILED(TF_CreateInputProcessorProfiles(&cpProfileMgr)))
  140. goto Exit;
  141. cpProfileMgr->EnableLanguageProfileByDefault( CLSID_SapiLayr,
  142. 0xffff,
  143. c_guidProfileBogus,
  144. FALSE);
  145. // Save the default property values to HKLM
  146. CSpPropItemsServer *pSpPropServer;
  147. pSpPropServer = (CSpPropItemsServer *) new CSpPropItemsServer;
  148. if ( pSpPropServer )
  149. {
  150. pSpPropServer->_SaveDefaultData( );
  151. delete pSpPropServer;
  152. }
  153. hr = S_OK;
  154. Exit:
  155. TFUninitLib( );
  156. return hr;
  157. }
  158. STDAPI DllUnregisterServer(void)
  159. {
  160. HRESULT hr = E_FAIL;
  161. TFInitLib();
  162. if (COMBase_DllUnregisterServer() != S_OK)
  163. goto Exit;
  164. if (FAILED(UnregisterCategories(CLSID_SapiLayr, c_rgRegCat)))
  165. goto Exit;
  166. if (!UnregisterTIP(CLSID_SapiLayr))
  167. goto Exit;
  168. hr = S_OK;
  169. Exit:
  170. TFUninitLib( );
  171. return hr;
  172. }