/*********************************************************************** * GlobalFindAtomW (KERNEL32.@) * * Unicode version of GlobalFindAtomA. */ ATOM WINAPI GlobalFindAtomW( LPCWSTR str ) { ATOM atom = 0; if (!check_integral_atom( str, &atom )) { NTSTATUS status = NtFindAtom( str, strlenW( str ) * sizeof(WCHAR), &atom ); if (status) { SetLastError( RtlNtStatusToDosError( status ) ); atom = 0; } } return atom; }
/*********************************************************************** * GlobalFindAtomA (KERNEL32.@) * * Get the atom associated with a string. * * RETURNS * Success: The associated atom. * Failure: 0. */ ATOM WINAPI GlobalFindAtomA( LPCSTR str /* [in] Pointer to string to search for */ ) { ATOM atom = 0; if (!check_integral_atom( str, &atom )) { WCHAR buffer[MAX_ATOM_LEN]; DWORD len = MultiByteToWideChar( CP_ACP, 0, str, strlen(str), buffer, MAX_ATOM_LEN ); if (!len) SetLastError( ERROR_INVALID_PARAMETER ); else { NTSTATUS status = NtFindAtom( buffer, len * sizeof(WCHAR), &atom ); if (status) { SetLastError( RtlNtStatusToDosError( status ) ); atom = 0; } } } return atom; }
ATOM WINAPI InternalFindAtom(BOOLEAN Local, BOOLEAN Unicode, LPCSTR AtomName) { NTSTATUS Status; ANSI_STRING AnsiString; UNICODE_STRING UnicodeString; PUNICODE_STRING AtomNameString; ATOM Atom = INVALID_ATOM; /* Check if it's an integer atom */ if ((ULONG_PTR)AtomName <= 0xFFFF) { /* Convert the name to an atom */ Atom = (ATOM)PtrToShort((PVOID)AtomName); if (Atom >= MAXINTATOM) { /* Fail, atom number too large */ BaseSetLastNTError(STATUS_INVALID_PARAMETER); DPRINT1("Invalid atom\n"); } /* Return it */ return Atom; } else { /* Check if this is a unicode atom */ if (Unicode) { /* Use a unicode string */ AtomNameString = &UnicodeString; RtlInitUnicodeString(AtomNameString, (LPWSTR)AtomName); Status = STATUS_SUCCESS; } else { /* Use an ansi string */ RtlInitAnsiString(&AnsiString, AtomName); /* Check if we can abuse the TEB */ if (AnsiString.MaximumLength > 260) { /* We can't, allocate a new string */ AtomNameString = &UnicodeString; Status = RtlAnsiStringToUnicodeString(AtomNameString, &AnsiString, TRUE); } else { /* We can! Get the TEB String */ AtomNameString = &NtCurrentTeb()->StaticUnicodeString; /* Convert it into the TEB */ Status = RtlAnsiStringToUnicodeString(AtomNameString, &AnsiString, FALSE); } } /* Check for failure */ if (!NT_SUCCESS(Status)) { DPRINT1("Failed\n"); BaseSetLastNTError(Status); return Atom; } } /* Check if we're doing local lookup */ if (Local) { /* Do a local lookup */ Status = RtlLookupAtomInAtomTable(InternalInitAtomTable(), AtomNameString->Buffer, &Atom); } else { /* Do a global search */ if (!AtomNameString->Length) { /* This is illegal in win32 */ DPRINT1("No name given\n"); Status = STATUS_OBJECT_NAME_NOT_FOUND; } else { /* Call the global function */ Status = NtFindAtom(AtomNameString->Buffer, AtomNameString->Length, &Atom); } } /* Check for failure */ if (!NT_SUCCESS(Status)) BaseSetLastNTError(Status); /* Check if we were non-static ANSI */ if (!(Unicode) && (AtomNameString == &UnicodeString)) { /* Free the allocated buffer */ RtlFreeUnicodeString(AtomNameString); } /* Return the atom */ return Atom; }