GlobalAddAtom

2.x

  ATOM GlobalAddAtom(lpszString)    
  LPCSTR lpszString; /* address of string to add */

The GlobalAddAtom function adds a string to the system atom table and returns a unique value identifying the string.

Parameters

lpszString

Points to the null-terminated string to be added. The case of the first string added is preserved and returned by the GlobalGetAtomName function. Strings that differ only in case are considered identical.

Return Value

The return value identifies the string if the function is successful. Otherwise, it is zero.

Comments

If the string exists already in the system atom table, the atom for the existing string will be returned and the atom's reference count will be incremented (increased by one). The string associated with the atom will not be deleted from memory until its reference count is zero. For more information, see the description of the GlobalDeleteAtom function.

Global atoms are not deleted automatically when the application terminates. For every call to the GlobalAddAtom function, there must be a corresponding call to the GlobalDeleteAtom function.

Example

The following example adds the string “This is a global atom” to the system atom table:

ATOM atom;
char szMsg[80];

atom = GlobalAddAtom("This is a global atom");

if (atom == 0)
    MessageBox(hwnd, "GlobalAddAtom failed", "",
         MB_ICONSTOP);
else {
    wsprintf(szMsg, "GlobalAddAtom returned %u", atom);
    MessageBox(hwnd, szMsg, "", MB_OK);
}

See Also

AddAtom, GlobalDeleteAtom, GlobalGetAtomName