3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/misc/atom.c
6 * PURPOSE: Atom functions
7 * PROGRAMMER: Eric Kohl ( ariadne@xs4all.nl)
10 * Full rewrite 27/05/2001
16 #include <kernel32/kernel32.h>
19 /* GLOBALS *******************************************************************/
21 static PRTL_ATOM_TABLE LocalAtomTable = NULL;
23 static PRTL_ATOM_TABLE GetLocalAtomTable(VOID);
26 /* FUNCTIONS *****************************************************************/
29 GlobalAddAtomA(LPCSTR lpString)
31 UNICODE_STRING AtomName;
35 if (HIWORD((ULONG)lpString) == 0)
37 if ((ULONG)lpString >= 0xC000)
39 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
42 return (ATOM)LOWORD((ULONG)lpString);
45 RtlCreateUnicodeStringFromAsciiz(&AtomName,
48 Status = NtAddAtom(AtomName.Buffer,
50 RtlFreeUnicodeString(&AtomName);
51 if (!NT_SUCCESS(Status))
53 SetLastErrorByStatus(Status);
62 GlobalAddAtomW(LPCWSTR lpString)
67 if (HIWORD((ULONG)lpString) == 0)
69 if ((ULONG)lpString >= 0xC000)
71 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
74 return (ATOM)LOWORD((ULONG)lpString);
77 Status = NtAddAtom((LPWSTR)lpString,
79 if (!NT_SUCCESS(Status))
81 SetLastErrorByStatus(Status);
90 GlobalDeleteAtom(ATOM nAtom)
99 Status = NtDeleteAtom(nAtom);
100 if (!NT_SUCCESS(Status))
102 SetLastErrorByStatus(Status);
111 GlobalFindAtomA(LPCSTR lpString)
113 UNICODE_STRING AtomName;
117 if (HIWORD((ULONG)lpString) == 0)
119 if ((ULONG)lpString >= 0xC000)
121 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
124 return (ATOM)LOWORD((ULONG)lpString);
127 RtlCreateUnicodeStringFromAsciiz(&AtomName,
129 Status = NtFindAtom(AtomName.Buffer,
131 RtlFreeUnicodeString(&AtomName);
132 if (!NT_SUCCESS(Status))
134 SetLastErrorByStatus(Status);
143 GlobalFindAtomW(LPCWSTR lpString)
148 if (HIWORD((ULONG)lpString) == 0)
150 if ((ULONG)lpString >= 0xC000)
152 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
155 return (ATOM)LOWORD((ULONG)lpString);
158 Status = NtFindAtom((LPWSTR)lpString,
160 if (!NT_SUCCESS(Status))
162 SetLastErrorByStatus(Status);
171 GlobalGetAtomNameA(ATOM nAtom,
175 PATOM_BASIC_INFORMATION Buffer;
176 UNICODE_STRING AtomNameU;
177 ANSI_STRING AtomName;
182 BufferSize = sizeof(ATOM_BASIC_INFORMATION) + nSize * sizeof(WCHAR);
183 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
187 Status = NtQueryInformationAtom(nAtom,
188 AtomBasicInformation,
192 if (!NT_SUCCESS(Status))
194 RtlFreeHeap(RtlGetProcessHeap(),
200 RtlInitUnicodeString(&AtomNameU,
202 AtomName.Buffer = lpBuffer;
204 AtomName.MaximumLength = nSize;
205 RtlUnicodeStringToAnsiString(&AtomName,
209 ReturnLength = AtomName.Length;
210 RtlFreeHeap(RtlGetProcessHeap(),
219 GlobalGetAtomNameW(ATOM nAtom,
223 PATOM_BASIC_INFORMATION Buffer;
228 BufferSize = sizeof(ATOM_BASIC_INFORMATION) + nSize * sizeof(WCHAR);
229 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
233 Status = NtQueryInformationAtom(nAtom,
234 AtomBasicInformation,
238 if (!NT_SUCCESS(Status))
240 RtlFreeHeap(RtlGetProcessHeap(),
246 wcscpy(lpBuffer, Buffer->Name);
247 ReturnLength = Buffer->NameLength / sizeof(WCHAR);
248 RtlFreeHeap(RtlGetProcessHeap(),
256 static PRTL_ATOM_TABLE
257 GetLocalAtomTable(VOID)
259 if (LocalAtomTable != NULL)
261 return LocalAtomTable;
263 RtlCreateAtomTable(37,
265 return LocalAtomTable;
270 InitAtomTable(DWORD nSize)
274 /* nSize should be a prime number */
276 if ( nSize < 4 || nSize >= 512 )
281 if (LocalAtomTable == NULL)
283 Status = RtlCreateAtomTable(nSize,
285 if (!NT_SUCCESS(Status))
287 SetLastErrorByStatus(Status);
297 AddAtomA(LPCSTR lpString)
299 PRTL_ATOM_TABLE AtomTable;
300 UNICODE_STRING AtomName;
304 if (HIWORD((ULONG)lpString) == 0)
306 if ((ULONG)lpString >= 0xC000)
308 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
311 return (ATOM)LOWORD((ULONG)lpString);
314 AtomTable = GetLocalAtomTable();
316 RtlCreateUnicodeStringFromAsciiz(&AtomName,
319 Status = RtlAddAtomToAtomTable(AtomTable,
322 RtlFreeUnicodeString(&AtomName);
323 if (!NT_SUCCESS(Status))
325 SetLastErrorByStatus(Status);
334 AddAtomW(LPCWSTR lpString)
336 PRTL_ATOM_TABLE AtomTable;
340 if (HIWORD((ULONG)lpString) == 0)
342 if ((ULONG)lpString >= 0xC000)
344 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
347 return (ATOM)LOWORD((ULONG)lpString);
350 AtomTable = GetLocalAtomTable();
352 Status = RtlAddAtomToAtomTable(AtomTable,
355 if (!NT_SUCCESS(Status))
357 SetLastErrorByStatus(Status);
366 DeleteAtom(ATOM nAtom)
368 PRTL_ATOM_TABLE AtomTable;
376 AtomTable = GetLocalAtomTable();
378 Status = RtlDeleteAtomFromAtomTable(AtomTable,
380 if (!NT_SUCCESS(Status))
382 SetLastErrorByStatus(Status);
391 FindAtomA(LPCSTR lpString)
393 PRTL_ATOM_TABLE AtomTable;
394 UNICODE_STRING AtomName;
398 if (HIWORD((ULONG)lpString) == 0)
400 if ((ULONG)lpString >= 0xC000)
402 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
405 return (ATOM)LOWORD((ULONG)lpString);
408 AtomTable = GetLocalAtomTable();
409 RtlCreateUnicodeStringFromAsciiz(&AtomName,
411 Status = RtlLookupAtomInAtomTable(AtomTable,
414 RtlFreeUnicodeString(&AtomName);
415 if (!NT_SUCCESS(Status))
417 SetLastErrorByStatus(Status);
426 FindAtomW(LPCWSTR lpString)
428 PRTL_ATOM_TABLE AtomTable;
432 if (HIWORD((ULONG)lpString) == 0)
434 if ((ULONG)lpString >= 0xC000)
436 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
439 return (ATOM)LOWORD((ULONG)lpString);
442 AtomTable = GetLocalAtomTable();
444 Status = RtlLookupAtomInAtomTable(AtomTable,
447 if (!NT_SUCCESS(Status))
449 SetLastErrorByStatus(Status);
458 GetAtomNameA(ATOM nAtom,
462 PRTL_ATOM_TABLE AtomTable;
464 UNICODE_STRING AtomNameU;
465 ANSI_STRING AtomName;
469 AtomTable = GetLocalAtomTable();
471 NameLength = nSize * sizeof(WCHAR);
472 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
476 Status = RtlQueryAtomInAtomTable(AtomTable,
482 if (!NT_SUCCESS(Status))
484 RtlFreeHeap(RtlGetProcessHeap(),
490 RtlInitUnicodeString(&AtomNameU,
492 AtomName.Buffer = lpBuffer;
494 AtomName.MaximumLength = nSize;
495 RtlUnicodeStringToAnsiString(&AtomName,
499 NameLength = AtomName.Length;
500 RtlFreeHeap(RtlGetProcessHeap(),
509 GetAtomNameW(ATOM nAtom,
513 PRTL_ATOM_TABLE AtomTable;
517 AtomTable = GetLocalAtomTable();
519 NameLength = nSize * sizeof(WCHAR);
520 Status = RtlQueryAtomInAtomTable(AtomTable,
526 if (!NT_SUCCESS(Status))
531 return(NameLength / sizeof(WCHAR));