17defa183c37c68534a8da7e00240226e37bf12c
[reactos.git] / reactos / win32ss / user / ntuser / useratom.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: User Atom helper routines
5 * FILE: subsys/win32k/ntuser/useratom.c
6 * PROGRAMER: Filip Navara <xnavara@volny.cz>
7 */
8
9 #include <win32k.h>
10 DBG_DEFAULT_CHANNEL(UserMisc);
11
12 RTL_ATOM FASTCALL
13 IntAddAtom(LPWSTR AtomName)
14 {
15 NTSTATUS Status = STATUS_SUCCESS;
16 PTHREADINFO pti;
17 RTL_ATOM Atom;
18
19 pti = PsGetCurrentThreadWin32Thread();
20 if (pti->rpdesk == NULL)
21 {
22 SetLastNtError(Status);
23 return (RTL_ATOM)0;
24 }
25
26 Status = RtlAddAtomToAtomTable(gAtomTable, AtomName, &Atom);
27
28 if (!NT_SUCCESS(Status))
29 {
30 SetLastNtError(Status);
31 return (RTL_ATOM)0;
32 }
33 return Atom;
34 }
35
36 ULONG FASTCALL
37 IntGetAtomName(RTL_ATOM nAtom, LPWSTR lpBuffer, ULONG nSize)
38 {
39 NTSTATUS Status = STATUS_SUCCESS;
40 PTHREADINFO pti;
41 ULONG Size = nSize;
42
43 pti = PsGetCurrentThreadWin32Thread();
44 if (pti->rpdesk == NULL)
45 {
46 SetLastNtError(Status);
47 return 0;
48 }
49
50 Status = RtlQueryAtomInAtomTable(gAtomTable, nAtom, NULL, NULL, lpBuffer, &Size);
51
52 if (Size < nSize)
53 *(lpBuffer + Size/sizeof(WCHAR)) = 0;
54 if (!NT_SUCCESS(Status))
55 {
56 SetLastNtError(Status);
57 return 0;
58 }
59 return Size;
60 }
61
62 RTL_ATOM FASTCALL
63 IntAddGlobalAtom(LPWSTR lpBuffer, BOOL PinAtom)
64 {
65 RTL_ATOM Atom;
66 NTSTATUS Status = STATUS_SUCCESS;
67
68 Status = RtlAddAtomToAtomTable(gAtomTable, lpBuffer, &Atom);
69
70 if (!NT_SUCCESS(Status))
71 {
72 ERR("Error init Global Atom.\n");
73 return 0;
74 }
75
76 if ( Atom && PinAtom ) RtlPinAtomInAtomTable(gAtomTable, Atom);
77
78 return Atom;
79 }
80
81 DWORD
82 APIENTRY
83 NtUserGetAtomName(
84 ATOM nAtom,
85 PUNICODE_STRING pBuffer)
86 {
87 DWORD Ret;
88 WCHAR Buffer[256];
89 UNICODE_STRING CapturedName = {0};
90 UserEnterShared();
91 CapturedName.Buffer = (LPWSTR)&Buffer;
92 CapturedName.MaximumLength = sizeof(Buffer);
93 Ret = IntGetAtomName((RTL_ATOM)nAtom, CapturedName.Buffer, (ULONG)CapturedName.Length);
94 _SEH2_TRY
95 {
96 RtlCopyMemory(pBuffer->Buffer, &Buffer, pBuffer->MaximumLength);
97 }
98 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
99 {
100 Ret = 0;
101 }
102 _SEH2_END
103 UserLeave();
104 return Ret;
105 }
106
107 /* EOF */