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.

347 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1999.
  5. //
  6. // File: langreg.hxx
  7. //
  8. // Contents: Macros for Self-registration of Word Breakers and Stemmers
  9. //
  10. // Functions: Macros to create DllRegisterServer, DllUnregisterServer
  11. //
  12. // History: 05-Jan-99 AlanW Created from filtreg.hxx
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. //
  17. // Structure to define language resource class
  18. //
  19. struct SLangClassEntry
  20. {
  21. WCHAR const * pwszClassId;
  22. WCHAR const * pwszClassIdDescription;
  23. WCHAR const * pwszDLL;
  24. WCHAR const * pwszThreadingModel;
  25. };
  26. struct SLangRegistry
  27. {
  28. WCHAR const * pwszLangName;
  29. LONG lcid;
  30. SLangClassEntry WordBreaker;
  31. SLangClassEntry Stemmer;
  32. };
  33. //
  34. // Sample use of the structures
  35. //
  36. //
  37. // SLangClassEntry const NeutralWordBreaker =
  38. // { L"{369647e0-17b0-11ce-9950-00aa004bbb1f}",
  39. // L"Neutral Word Breaker",
  40. // L"query.dll",
  41. // L"both" };
  42. //
  43. // SLangRegistry const English_US_LangRes =
  44. // { L"English_US", 1033,
  45. // { L"{59e09780-8099-101b-8df3-00000b65c3b5}",
  46. // L"English_US Word Breaker",
  47. // L"infosoft.dll",
  48. // L"both" },
  49. // { L"{eeed4c20-7f1b-11ce-be57-00aa0051fe20}",
  50. // L"English_US Stemmer",
  51. // L"infosoft.dll",
  52. // L"both" }
  53. // };
  54. //
  55. //
  56. // Function prototypes
  57. //
  58. inline long RegisterALanguageResource( SLangRegistry const & LangRes );
  59. inline long RegisterALanguageClass( SLangClassEntry const & LangClass );
  60. inline long UnRegisterALanguageResource( SLangRegistry const & LangRes );
  61. inline long UnRegisterALanguageClass( SLangClassEntry const & LangClass );
  62. //+---------------------------------------------------------------------------
  63. //
  64. // Function: RegisterALanguageResource, private
  65. //
  66. // Synopsis: Registers a language resource.
  67. //
  68. // Arguments: [LangRes] -- Language resource description
  69. //
  70. // Returns: ERROR_SUCCESS on success
  71. //
  72. // History: 05-Jan-99 AlanW Created
  73. //
  74. //----------------------------------------------------------------------------
  75. inline long RegisterALanguageResource( SLangRegistry const & LangRes )
  76. {
  77. WCHAR wcTemp[MAX_PATH];
  78. long dwError;
  79. HKEY hKey = (HKEY)INVALID_HANDLE_VALUE;
  80. wcscpy( wcTemp, L"System\\CurrentControlSet\\Control\\ContentIndex\\Language\\" );
  81. if ( ( wcslen( wcTemp ) + wcslen( LangRes.pwszLangName ) ) >= MAX_PATH )
  82. return ERROR_INSUFFICIENT_BUFFER;
  83. wcscat( wcTemp, LangRes.pwszLangName );
  84. do
  85. {
  86. DWORD dwDisposition;
  87. dwError = RegCreateKeyExW( HKEY_LOCAL_MACHINE, // Root
  88. wcTemp, // Sub key
  89. 0, // Reserved
  90. 0, // Class
  91. 0, // Flags
  92. KEY_ALL_ACCESS, // Access
  93. 0, // Security
  94. &hKey, // Handle
  95. &dwDisposition ); // Disposition
  96. if ( ERROR_SUCCESS != dwError )
  97. break;
  98. //
  99. // Write the locale ID
  100. //
  101. dwError = RegSetValueExW( hKey, // Key
  102. L"Locale", // Name
  103. 0, // Reserved
  104. REG_DWORD, // Type
  105. (BYTE *)&LangRes.lcid, // Value
  106. sizeof DWORD );
  107. if ( ERROR_SUCCESS != dwError )
  108. break;
  109. //
  110. // Create the word breaker class description
  111. //
  112. if (LangRes.WordBreaker.pwszClassId != 0)
  113. {
  114. dwError = RegisterALanguageClass( LangRes.WordBreaker );
  115. if ( ERROR_SUCCESS != dwError )
  116. break;
  117. dwError = RegSetValueExW( hKey, // Key
  118. L"WBreakerClass", // Name
  119. 0, // Reserved
  120. REG_SZ, // Type
  121. (BYTE *)LangRes.WordBreaker.pwszClassId, // Value
  122. (1 + wcslen(LangRes.WordBreaker.pwszClassId) ) * sizeof(WCHAR) );
  123. if ( ERROR_SUCCESS != dwError )
  124. break;
  125. }
  126. //
  127. // Create the stemmer class description
  128. //
  129. if (LangRes.Stemmer.pwszClassId != 0)
  130. {
  131. dwError = RegisterALanguageClass( LangRes.Stemmer );
  132. if ( ERROR_SUCCESS != dwError )
  133. break;
  134. dwError = RegSetValueExW( hKey, // Key
  135. L"StemmerClass", // Name
  136. 0, // Reserved
  137. REG_SZ, // Type
  138. (BYTE *)LangRes.Stemmer.pwszClassId, // Value
  139. (1 + wcslen(LangRes.Stemmer.pwszClassId) ) * sizeof(WCHAR) );
  140. if ( ERROR_SUCCESS != dwError )
  141. break;
  142. }
  143. } while( FALSE );
  144. if ( (HKEY)INVALID_HANDLE_VALUE != hKey )
  145. {
  146. RegCloseKey( hKey );
  147. hKey = (HKEY)INVALID_HANDLE_VALUE;
  148. }
  149. return dwError;
  150. }
  151. //+---------------------------------------------------------------------------
  152. //
  153. // Function: UnRegisterALanguageResource, private
  154. //
  155. // Synopsis: Unregisters a language resource.
  156. //
  157. // Arguments: [LangRes] -- Language resource description
  158. //
  159. // Returns: ERROR_SUCCESS on success
  160. //
  161. // History: 05-Jan-99 AlanW Created
  162. //
  163. //----------------------------------------------------------------------------
  164. inline long UnRegisterALanguageResource( SLangRegistry const & LangRes )
  165. {
  166. WCHAR wcTemp[MAX_PATH];
  167. wcscpy( wcTemp, L"System\\CurrentControlSet\\Control\\ContentIndex\\Language\\" );
  168. if ( ( wcslen( wcTemp ) + wcslen( LangRes.pwszLangName ) ) >= MAX_PATH )
  169. return ERROR_INSUFFICIENT_BUFFER;
  170. wcscat( wcTemp, LangRes.pwszLangName );
  171. HKEY hKey = (HKEY)INVALID_HANDLE_VALUE;
  172. long dwError = RegOpenKeyExW( HKEY_LOCAL_MACHINE, // Root
  173. wcTemp, // Sub key
  174. 0, // Reserved
  175. KEY_ALL_ACCESS, // Access
  176. &hKey ); // Handle
  177. //
  178. // Delete the word breaker class description
  179. //
  180. if (LangRes.WordBreaker.pwszClassId != 0)
  181. {
  182. dwError = UnRegisterALanguageClass( LangRes.WordBreaker );
  183. if (hKey != INVALID_HANDLE_VALUE)
  184. dwError = RegDeleteValueW( hKey, // Key
  185. L"WBreakerClass" ); // Name
  186. }
  187. //
  188. // Create the stemmer class description
  189. //
  190. if (LangRes.Stemmer.pwszClassId != 0)
  191. {
  192. dwError = UnRegisterALanguageClass( LangRes.Stemmer );
  193. if (hKey != INVALID_HANDLE_VALUE)
  194. dwError = RegDeleteValueW( hKey, // Key
  195. L"StemmerClass" ); // Name
  196. }
  197. if (hKey != INVALID_HANDLE_VALUE)
  198. {
  199. DWORD dwNumofKeys = 0;
  200. DWORD dwNumofValues = 0;
  201. dwError = RegQueryInfoKeyW( hKey, // Hkey
  202. 0, // Buffer for class string
  203. 0, // Size of class string buffer
  204. 0, // reserved
  205. &dwNumofKeys,// number of subkeys
  206. 0, // longest subkey name length
  207. 0, // longest class string length
  208. &dwNumofValues,// number of value entries
  209. 0, // longest value name length
  210. 0, // longest value data length
  211. 0, // security descriptor length
  212. 0 ); // last write time);
  213. if ( ERROR_SUCCESS == dwError )
  214. {
  215. if ( (dwNumofValues == 1) && (dwNumofKeys==0) )
  216. {
  217. //
  218. // There is only one value and no sub-keys under this key,
  219. // Delete the Locale value and then the sub-key for this Lang
  220. // if that succeeded.
  221. //
  222. RegDeleteValueW( hKey, // Key
  223. L"Locale" ); // Name
  224. dwError = RegQueryInfoKeyW( hKey, // Hkey
  225. 0, // class string
  226. 0, // Size of class string
  227. 0, // reserved
  228. &dwNumofKeys,
  229. 0, // max subkey name len
  230. 0, // max class string len
  231. &dwNumofValues,
  232. 0, // max value name len
  233. 0, // max value data len
  234. 0, // security desc len
  235. 0 ); // last write time);
  236. }
  237. }
  238. RegCloseKey( hKey );
  239. if ( ERROR_SUCCESS == dwError &&
  240. (0 == dwNumofValues) &&
  241. (0 == dwNumofKeys) )
  242. dwError = RegDeleteKeyW( HKEY_LOCAL_MACHINE, // Root
  243. wcTemp ); // Sub key
  244. }
  245. return dwError;
  246. }
  247. //+---------------------------------------------------------------------------
  248. //
  249. // Function: RegisterALanguageClass, private
  250. //
  251. // Synopsis: Registers a language resource classID in registry
  252. //
  253. // Arguments: [LangClass] -- IWordBreaker or IStemmer description
  254. //
  255. // Returns: ERROR_SUCCESS on success
  256. //
  257. // History: 05-Jan-99 AlanW Created
  258. //
  259. //----------------------------------------------------------------------------
  260. inline long RegisterALanguageClass( SLangClassEntry const & LangClass )
  261. {
  262. WCHAR const * aKeyValues[4] = { LangClass.pwszClassId,
  263. LangClass.pwszClassIdDescription,
  264. L"InprocServer32",
  265. LangClass.pwszDLL };
  266. long retVal = BuildKeyValues( aKeyValues, sizeof(aKeyValues)/sizeof(aKeyValues[0]) );
  267. if ( ERROR_SUCCESS == retVal )
  268. retVal = AddThreadingModel( LangClass.pwszClassId, LangClass.pwszThreadingModel );
  269. return retVal;
  270. }
  271. //+---------------------------------------------------------------------------
  272. //
  273. // Function: UnRegisterALanguageClass, private
  274. //
  275. // Synopsis: Unregisters a language resource classID
  276. //
  277. // Arguments: [LangClass] -- IWordBreaker or IStemmer description
  278. //
  279. // Returns: ERROR_SUCCESS on success
  280. //
  281. // History: 05-Jan-99 AlanW Created
  282. //
  283. //----------------------------------------------------------------------------
  284. inline long UnRegisterALanguageClass( SLangClassEntry const & LangClass )
  285. {
  286. WCHAR const * aKeyValues[4] = { LangClass.pwszClassId,
  287. LangClass.pwszClassIdDescription,
  288. L"InprocServer32",
  289. LangClass.pwszDLL };
  290. return DestroyKeyValues( aKeyValues, sizeof(aKeyValues)/sizeof(aKeyValues[0]) );
  291. }