ReactOS 0.4.16-dev-2274-gc61d98f
atomansi.c File Reference
#include <k32.h>
Include dependency graph for atomansi.c:

Go to the source code of this file.

Functions

ATOM WINAPI InternalAddAtom (BOOLEAN Local, BOOLEAN Unicode, LPCSTR AtomName)
 
ATOM WINAPI InternalFindAtom (BOOLEAN Local, BOOLEAN Unicode, LPCSTR AtomName)
 
ATOM WINAPI GlobalAddAtomA (LPCSTR lpString)
 
ATOM WINAPI GlobalFindAtomA (LPCSTR lpString)
 

Function Documentation

◆ GlobalAddAtomA()

ATOM WINAPI GlobalAddAtomA ( LPCSTR  lpString)

Definition at line 23 of file atomansi.c.

24{
25 return InternalAddAtom(FALSE, FALSE, lpString);
26}
ATOM WINAPI InternalAddAtom(BOOLEAN Local, BOOLEAN Unicode, LPCSTR AtomName)
Definition: atom.c:32
#define FALSE
Definition: types.h:117

Referenced by test_add_atom(), test_error_handling(), test_get_atom_name(), test_handles(), and test_msg_client().

◆ GlobalFindAtomA()

ATOM WINAPI GlobalFindAtomA ( LPCSTR  lpString)

Definition at line 33 of file atomansi.c.

34{
35 return InternalFindAtom(FALSE, FALSE, lpString);
36}
ATOM WINAPI InternalFindAtom(BOOLEAN Local, BOOLEAN Unicode, LPCSTR AtomName)
Definition: atom.c:133

Referenced by test_add_atom(), test_DdeCreateStringHandleW(), test_error_handling(), and test_RegisterClipboardFormatA().

◆ InternalAddAtom()

ATOM WINAPI InternalAddAtom ( BOOLEAN  Local,
BOOLEAN  Unicode,
LPCSTR  AtomName 
)

Definition at line 32 of file atom.c.

35{
39 PUNICODE_STRING AtomNameString;
41
42 /* Check if it's an integer atom */
43 if ((ULONG_PTR)AtomName <= 0xFFFF)
44 {
45 /* Convert the name to an atom */
46 Atom = (ATOM)PtrToShort((PVOID)AtomName);
47 if (Atom >= MAXINTATOM)
48 {
49 /* Fail, atom number too large */
51 return INVALID_ATOM;
52 }
53
54 /* Return it */
55 return Atom;
56 }
57 else
58 {
59 /* Check if this is a unicode atom */
60 if (Unicode)
61 {
62 /* Use a unicode string */
63 AtomNameString = &UnicodeString;
64 RtlInitUnicodeString(AtomNameString, (LPWSTR)AtomName);
66 }
67 else
68 {
69 /* Use an ansi string */
70 RtlInitAnsiString(&AnsiString, AtomName );
71
72 /* Check if we can abuse the TEB */
73 if (AnsiString.MaximumLength > 260)
74 {
75 /* We can't, allocate a new string */
76 AtomNameString = &UnicodeString;
77 Status = RtlAnsiStringToUnicodeString(AtomNameString,
79 TRUE);
80 }
81 else
82 {
83 /* We can! Get the TEB String */
84 AtomNameString = &NtCurrentTeb()->StaticUnicodeString;
85
86 /* Convert it into the TEB */
87 Status = RtlAnsiStringToUnicodeString(AtomNameString,
89 FALSE);
90 }
91 }
92
93 /* Check for failure */
94 if (!NT_SUCCESS(Status))
95 {
97 return Atom;
98 }
99 }
100
101 /* Check if we're doing local add */
102 if (Local)
103 {
104 /* Do a local add */
106 AtomNameString->Buffer,
107 &Atom);
108 }
109 else
110 {
111 /* Do a global add */
112 Status = NtAddAtom(AtomNameString->Buffer,
113 AtomNameString->Length,
114 &Atom);
115 }
116
117 /* Check for failure */
119
120 /* Check if we were non-static ANSI */
121 if (!(Unicode) && (AtomNameString == &UnicodeString))
122 {
123 /* Free the allocated buffer */
124 RtlFreeUnicodeString(AtomNameString);
125 }
126
127 /* Return the atom */
128 return Atom;
129}
LONG NTSTATUS
Definition: precomp.h:26
#define PtrToShort(p)
Definition: basetsd.h:82
_Out_ RTL_ATOM * Atom
Definition: class.h:54
WORD ATOM
Definition: dimm.idl:113
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
PVOID WINAPI InternalInitAtomTable(VOID)
Definition: atom.c:23
@ AnsiString
Definition: dnslib.h:19
Status
Definition: gdiplustypes.h:25
#define NtCurrentTeb
NTSYSAPI NTSTATUS NTAPI RtlAddAtomToAtomTable(_In_ PRTL_ATOM_TABLE AtomTable, _In_ PWSTR AtomName, _Out_ PRTL_ATOM Atom)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
NTSTATUS NTAPI NtAddAtom(IN PWSTR AtomName, IN ULONG AtomNameLength, OUT PRTL_ATOM Atom)
Definition: atom.c:86
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define INVALID_ATOM
Definition: winbase.h:427
#define MAXINTATOM
Definition: winbase.h:426
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by AddAtomA(), AddAtomW(), GlobalAddAtomA(), and GlobalAddAtomW().

◆ InternalFindAtom()

ATOM WINAPI InternalFindAtom ( BOOLEAN  Local,
BOOLEAN  Unicode,
LPCSTR  AtomName 
)

Definition at line 133 of file atom.c.

136{
140 PUNICODE_STRING AtomNameString;
142
143 /* Check if it's an integer atom */
144 if ((ULONG_PTR)AtomName <= 0xFFFF)
145 {
146 /* Convert the name to an atom */
147 Atom = (ATOM)PtrToShort((PVOID)AtomName);
148 if (Atom >= MAXINTATOM)
149 {
150 /* Fail, atom number too large */
152 DPRINT1("Invalid atom\n");
153 }
154
155 /* Return it */
156 return Atom;
157 }
158 else
159 {
160 /* Check if this is a unicode atom */
161 if (Unicode)
162 {
163 /* Use a unicode string */
164 AtomNameString = &UnicodeString;
165 RtlInitUnicodeString(AtomNameString, (LPWSTR)AtomName);
167 }
168 else
169 {
170 /* Use an ansi string */
171 RtlInitAnsiString(&AnsiString, AtomName);
172
173 /* Check if we can abuse the TEB */
174 if (AnsiString.MaximumLength > 260)
175 {
176 /* We can't, allocate a new string */
177 AtomNameString = &UnicodeString;
178 Status = RtlAnsiStringToUnicodeString(AtomNameString,
179 &AnsiString,
180 TRUE);
181 }
182 else
183 {
184 /* We can! Get the TEB String */
185 AtomNameString = &NtCurrentTeb()->StaticUnicodeString;
186
187 /* Convert it into the TEB */
188 Status = RtlAnsiStringToUnicodeString(AtomNameString,
189 &AnsiString,
190 FALSE);
191 }
192 }
193
194 /* Check for failure */
195 if (!NT_SUCCESS(Status))
196 {
197 DPRINT1("Failed\n");
199 return Atom;
200 }
201 }
202
203 /* Check if we're doing local lookup */
204 if (Local)
205 {
206 /* Do a local lookup */
208 AtomNameString->Buffer,
209 &Atom);
210 }
211 else
212 {
213 /* Do a global search */
214 if (!AtomNameString->Length)
215 {
216 /* This is illegal in win32 */
217 DPRINT1("No name given\n");
219 }
220 else
221 {
222 /* Call the global function */
223 Status = NtFindAtom(AtomNameString->Buffer,
224 AtomNameString->Length,
225 &Atom);
226 }
227 }
228
229 /* Check for failure */
231
232 /* Check if we were non-static ANSI */
233 if (!(Unicode) && (AtomNameString == &UnicodeString))
234 {
235 /* Free the allocated buffer */
236 RtlFreeUnicodeString(AtomNameString);
237 }
238
239 /* Return the atom */
240 return Atom;
241}
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI NTSTATUS NTAPI RtlLookupAtomInAtomTable(_In_ PRTL_ATOM_TABLE AtomTable, _In_ PWSTR AtomName, _Out_ PRTL_ATOM Atom)
NTSTATUS NTAPI NtFindAtom(IN PWSTR AtomName, IN ULONG AtomNameLength, OUT PRTL_ATOM Atom)
Definition: atom.c:243
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by FindAtomA(), FindAtomW(), GlobalFindAtomA(), and GlobalFindAtomW().