Source code of Windows XP (NT5)
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.

109 lines
2.6 KiB

  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1997, Microsoft Corporation.
  4. //
  5. // Routine: DllMain
  6. //
  7. // Description:
  8. //
  9. // Returns: True if successful, else False.
  10. // History: Weibz, 10-Nov-1997, created it.
  11. //
  12. //---------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #include "thwbint.h"
  15. #include "resource.h"
  16. CRITICAL_SECTION ThCritSect;
  17. //SCRIPTITEMIZE ScriptItemize;
  18. //SCRIPTBREAK ScriptBreak;
  19. HMODULE hUsp;
  20. BOOL InitWordBreakEngine(HINSTANCE hInstance);
  21. BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
  22. {
  23. CHAR szUSPPath[MAX_PATH];
  24. switch(dwReason)
  25. {
  26. case DLL_PROCESS_ATTACH :
  27. DisableThreadLibraryCalls(hDLL);
  28. InitializeCriticalSection (&ThCritSect);
  29. /*
  30. GetSystemDirectory ( szUSPPath, MAX_PATH );
  31. strcat ( szUSPPath, "\\USP.DLL" );
  32. hUsp = LoadLibrary (szUSPPath);
  33. if ( hUsp == NULL )
  34. return FALSE;
  35. ScriptItemize = (SCRIPTITEMIZE)GetProcAddress(hUsp,"ScriptItemize");
  36. ScriptBreak = (SCRIPTBREAK) GetProcAddress(hUsp,"ScriptBreak");
  37. if ( (ScriptItemize==NULL) || (ScriptBreak==NULL) )
  38. return FALSE;
  39. */
  40. return InitWordBreakEngine(hDLL);
  41. break ;
  42. case DLL_THREAD_ATTACH:
  43. break;
  44. case DLL_THREAD_DETACH:
  45. break;
  46. case DLL_PROCESS_DETACH :
  47. /*
  48. if (hUsp != NULL )
  49. FreeLibrary(hUsp);
  50. hUsp = NULL;
  51. */
  52. ThaiWordBreakTerminate();
  53. DeleteCriticalSection (&ThCritSect);
  54. break ;
  55. } //switch
  56. return TRUE ;
  57. }
  58. BOOL InitWordBreakEngine(HINSTANCE hInstance)
  59. {
  60. LPBYTE lpLexicon = NULL;
  61. LPBYTE lpTrigram = NULL;
  62. HGLOBAL hLexicon = NULL;
  63. HGLOBAL hTrigram = NULL;
  64. HRSRC hrsrcLexicon = FindResource(hInstance,(LPSTR) MAKEINTRESOURCE(IDR_LEXICON1),"LEXICON");
  65. HRSRC hrsrcTrigram = FindResource(hInstance,(LPSTR) MAKEINTRESOURCE(IDR_LEXICON2),"LEXICON");
  66. // Check if we were able to find resource.
  67. if (NULL == hrsrcLexicon || NULL == hrsrcTrigram)
  68. {
  69. assert(false);
  70. return FALSE;
  71. }
  72. hLexicon = LoadResource(hInstance, hrsrcLexicon);
  73. hTrigram = LoadResource(hInstance, hrsrcTrigram);
  74. // Check if we were able to load resource.
  75. if (NULL == hLexicon || NULL == hTrigram)
  76. {
  77. assert(false);
  78. return FALSE;
  79. }
  80. lpLexicon = (LPBYTE) LockResource(hLexicon);
  81. lpTrigram = (LPBYTE) LockResource(hTrigram);
  82. if (ThaiWordBreakInitResource(lpLexicon,lpTrigram) != ptecNoErrors)
  83. {
  84. assert(false);
  85. return FALSE;
  86. }
  87. return TRUE;
  88. }