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 *****************************************************************/
32 GlobalAddAtomA(LPCSTR lpString)
34 UNICODE_STRING AtomName;
38 if (HIWORD((ULONG)lpString) == 0)
40 if ((ULONG)lpString >= 0xC000)
42 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
45 return (ATOM)LOWORD((ULONG)lpString);
48 RtlCreateUnicodeStringFromAsciiz(&AtomName,
51 Status = NtAddAtom(AtomName.Buffer,
53 RtlFreeUnicodeString(&AtomName);
54 if (!NT_SUCCESS(Status))
56 SetLastErrorByStatus(Status);
68 GlobalAddAtomW(LPCWSTR lpString)
73 if (HIWORD((ULONG)lpString) == 0)
75 if ((ULONG)lpString >= 0xC000)
77 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
80 return (ATOM)LOWORD((ULONG)lpString);
83 Status = NtAddAtom((LPWSTR)lpString,
85 if (!NT_SUCCESS(Status))
87 SetLastErrorByStatus(Status);
99 GlobalDeleteAtom(ATOM nAtom)
108 Status = NtDeleteAtom(nAtom);
109 if (!NT_SUCCESS(Status))
111 SetLastErrorByStatus(Status);
123 GlobalFindAtomA(LPCSTR lpString)
125 UNICODE_STRING AtomName;
129 if (HIWORD((ULONG)lpString) == 0)
131 if ((ULONG)lpString >= 0xC000)
133 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
136 return (ATOM)LOWORD((ULONG)lpString);
139 RtlCreateUnicodeStringFromAsciiz(&AtomName,
141 Status = NtFindAtom(AtomName.Buffer,
143 RtlFreeUnicodeString(&AtomName);
144 if (!NT_SUCCESS(Status))
146 SetLastErrorByStatus(Status);
158 GlobalFindAtomW(LPCWSTR lpString)
163 if (HIWORD((ULONG)lpString) == 0)
165 if ((ULONG)lpString >= 0xC000)
167 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
170 return (ATOM)LOWORD((ULONG)lpString);
173 Status = NtFindAtom((LPWSTR)lpString,
175 if (!NT_SUCCESS(Status))
177 SetLastErrorByStatus(Status);
186 GlobalGetAtomNameA(ATOM nAtom,
190 PATOM_BASIC_INFORMATION Buffer;
191 UNICODE_STRING AtomNameU;
192 ANSI_STRING AtomName;
197 BufferSize = sizeof(ATOM_BASIC_INFORMATION) + nSize * sizeof(WCHAR);
198 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
202 Status = NtQueryInformationAtom(nAtom,
203 AtomBasicInformation,
207 if (!NT_SUCCESS(Status))
209 RtlFreeHeap(RtlGetProcessHeap(),
215 RtlInitUnicodeString(&AtomNameU,
217 AtomName.Buffer = lpBuffer;
219 AtomName.MaximumLength = nSize;
220 RtlUnicodeStringToAnsiString(&AtomName,
224 ReturnLength = AtomName.Length;
225 RtlFreeHeap(RtlGetProcessHeap(),
237 GlobalGetAtomNameW(ATOM nAtom,
241 PATOM_BASIC_INFORMATION Buffer;
246 BufferSize = sizeof(ATOM_BASIC_INFORMATION) + nSize * sizeof(WCHAR);
247 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
251 Status = NtQueryInformationAtom(nAtom,
252 AtomBasicInformation,
256 if (!NT_SUCCESS(Status))
258 RtlFreeHeap(RtlGetProcessHeap(),
264 wcscpy(lpBuffer, Buffer->Name);
265 ReturnLength = Buffer->NameLength / sizeof(WCHAR);
266 RtlFreeHeap(RtlGetProcessHeap(),
274 static PRTL_ATOM_TABLE
275 GetLocalAtomTable(VOID)
277 if (LocalAtomTable != NULL)
279 return LocalAtomTable;
281 RtlCreateAtomTable(37,
283 return LocalAtomTable;
291 InitAtomTable(DWORD nSize)
295 /* nSize should be a prime number */
297 if ( nSize < 4 || nSize >= 512 )
302 if (LocalAtomTable == NULL)
304 Status = RtlCreateAtomTable(nSize,
306 if (!NT_SUCCESS(Status))
308 SetLastErrorByStatus(Status);
321 AddAtomA(LPCSTR lpString)
323 PRTL_ATOM_TABLE AtomTable;
324 UNICODE_STRING AtomName;
328 if (HIWORD((ULONG)lpString) == 0)
330 if ((ULONG)lpString >= 0xC000)
332 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
335 return (ATOM)LOWORD((ULONG)lpString);
338 AtomTable = GetLocalAtomTable();
340 RtlCreateUnicodeStringFromAsciiz(&AtomName,
343 Status = RtlAddAtomToAtomTable(AtomTable,
346 RtlFreeUnicodeString(&AtomName);
347 if (!NT_SUCCESS(Status))
349 SetLastErrorByStatus(Status);
361 AddAtomW(LPCWSTR lpString)
363 PRTL_ATOM_TABLE AtomTable;
367 if (HIWORD((ULONG)lpString) == 0)
369 if ((ULONG)lpString >= 0xC000)
371 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
374 return (ATOM)LOWORD((ULONG)lpString);
377 AtomTable = GetLocalAtomTable();
379 Status = RtlAddAtomToAtomTable(AtomTable,
382 if (!NT_SUCCESS(Status))
384 SetLastErrorByStatus(Status);
396 DeleteAtom(ATOM nAtom)
398 PRTL_ATOM_TABLE AtomTable;
406 AtomTable = GetLocalAtomTable();
408 Status = RtlDeleteAtomFromAtomTable(AtomTable,
410 if (!NT_SUCCESS(Status))
412 SetLastErrorByStatus(Status);
424 FindAtomA(LPCSTR lpString)
426 PRTL_ATOM_TABLE AtomTable;
427 UNICODE_STRING AtomName;
431 if (HIWORD((ULONG)lpString) == 0)
433 if ((ULONG)lpString >= 0xC000)
435 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
438 return (ATOM)LOWORD((ULONG)lpString);
441 AtomTable = GetLocalAtomTable();
442 RtlCreateUnicodeStringFromAsciiz(&AtomName,
444 Status = RtlLookupAtomInAtomTable(AtomTable,
447 RtlFreeUnicodeString(&AtomName);
448 if (!NT_SUCCESS(Status))
450 SetLastErrorByStatus(Status);
462 FindAtomW(LPCWSTR lpString)
464 PRTL_ATOM_TABLE AtomTable;
468 if (HIWORD((ULONG)lpString) == 0)
470 if ((ULONG)lpString >= 0xC000)
472 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
475 return (ATOM)LOWORD((ULONG)lpString);
478 AtomTable = GetLocalAtomTable();
480 Status = RtlLookupAtomInAtomTable(AtomTable,
483 if (!NT_SUCCESS(Status))
485 SetLastErrorByStatus(Status);
497 GetAtomNameA(ATOM nAtom,
501 PRTL_ATOM_TABLE AtomTable;
503 UNICODE_STRING AtomNameU;
504 ANSI_STRING AtomName;
508 AtomTable = GetLocalAtomTable();
510 NameLength = nSize * sizeof(WCHAR);
511 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
515 Status = RtlQueryAtomInAtomTable(AtomTable,
521 if (!NT_SUCCESS(Status))
523 RtlFreeHeap(RtlGetProcessHeap(),
529 RtlInitUnicodeString(&AtomNameU,
531 AtomName.Buffer = lpBuffer;
533 AtomName.MaximumLength = nSize;
534 RtlUnicodeStringToAnsiString(&AtomName,
538 NameLength = AtomName.Length;
539 RtlFreeHeap(RtlGetProcessHeap(),
551 GetAtomNameW(ATOM nAtom,
555 PRTL_ATOM_TABLE AtomTable;
559 AtomTable = GetLocalAtomTable();
561 NameLength = nSize * sizeof(WCHAR);
562 Status = RtlQueryAtomInAtomTable(AtomTable,
568 if (!NT_SUCCESS(Status))
573 return(NameLength / sizeof(WCHAR));