Using the Global Atom Table

It has been suggested that Windows allocates handles to Atoms on a sequential basis. i.e. if an application performs a GlobalAddAtom and the atom value 0xC000 is returned from the initial call, will it ALWAYS be the case that the next call to GlobalAddAtom will return the previous atom value + 1 - assume that atom strings are unique.

Or is there a risk that 'holes' may appear in the atom values? e.g. 0xC001, 0xC003, 0xC00A etc.


james_m_carrAsked:
Who is Participating?
 
Jaysin28Connect With a Mentor Commented:
the system generates an atom that is unique throughout the system. Any application that has the atom can obtain the string it identifies by querying the global atom table.
An application that defines a private DDE-data format for sharing data with other applications should place the format name in the global atom table. This technique prevents conflicts with the names of formats defined by the system or by other applications, and makes the identifiers (atoms) for the messages or formats available to the other applications.
An application creates a local atom by calling the AddAtom function; it creates a global atom by calling the GlobalAddAtom function. Both functions require a pointer to a string. The system searches the appropriate atom table for the string and returns the corresponding atom to the application. In the case of a string atom, if the string already resides in the atom table, the system increments the reference count for the string during this process.
Repeated calls to add the same atom name return the same atom. If the atom name does not exist in the table when AddAtom is called, the atom name is added to the table and a new atom is returned. If it is a string atom, its reference count is also set to one.
An application should call the DeleteAtom function when it no longer needs to use a local atom; it should call the GlobalDeleteAtom function when it no longer needs a global atom. In the case of a string atom, either of these functions reduces the reference count of the corresponding atom by one. When the reference count reaches zero, the system deletes the atom name from the table.
The atom name of a string atom remains in the global atom table as long as its reference count is greater than zero, even after the application that placed it in the table terminates. A local atom table is destroyed when the associated application terminates, regardless of the reference counts of the atoms in the table.
The GlobalAddAtom function adds a character string to the global atom table and returns a unique value (an atom) identifying the string.
ATOM GlobalAddAtom(
  LPCTSTR lpString   // pointer to the string to add
);
Parameters
lpString
Points to the null-terminated string to be added. The string can have a maximum size of 255 bytes. Strings that differ only in case are considered identical. The case of the first string of this name added to the table is preserved and returned by the GlobalGetAtomName function.
Alternatively, you can use an integer atom that has been converted using the MAKEINTATOM macro. See the Remarks for more information.
Return Values
If the function succeeds, the return value is the newly created atom.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
If the string already exists in the global atom table, the atom for the existing string is returned and the atom's reference count is incremented.
The string associated with the atom is not deleted from memory until its reference count is zero. For more information, see 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.
If the lpString parameter has the form "#1234", GlobalAddAtom returns an integer atom whose value is the 16-bit representation of the decimal number specified in the string (0x04D2, in this example). If the decimal value specified is 0x0000 or is greater than or equal to 0xC000, the return value is zero, indicating an error. If lpString was created by the MAKEINTATOM macro, the low-order word must be in the range 0x0001 through 0xBFFF. If the low-order word is not in this range, the function fails.
If lpString has any other form, GlobalAddAtom returns a string atom.

If you want more infor on the Global Atom Table copy the link below and paste into your browser.  This is information of Atom Tables straight from Microsoft.

http://search.microsoft.com/us/dev/results.asp?nq=TRUE&SName=&SPath=&SCatalog=&qu=Atom+Table&Finish=search&Boolean=PHRASE&chkM=on&radM=1&chkM_1=on&chkM_2=on&chkM_3=on&chkM_5=on&chkM_7=on&chkM_9=on&chkM_11=on&chkM_12=on&chkM_13=on&chkM_14=on&chkM_15=on&chkM_16=on&chkM_17=on&chkS=on&radS=0&chkS_0=on&chkS_1=on&chkS_2=on&chkS_3=on&chkS_4=on&chkS_5=on&chkS_6=on&chkS_7=on&chkS_8=on&chkS_9=on&chkS_10=on&chkS_11=on&chkS_12=on&chkS_13=on&mh=10&sh=10

0
All Courses

From novice to tech pro — start learning today.