MAKEINTATOM() Does Not Return a Valid LPSTRID: Q61980
|
The LPSTR returned from MAKEINTATOM() cannot be treated as a general-purpose string pointer. Instead, either use it with the Atom family or convert it into a valid string before passing it off as one.
The MAKEINTATOM() macro is documented on Page 370 of the "Microsoft
Windows Software Development Kit Programmer's Reference" versions 2.x
as returning a value of type LPSTR. This is correct, but misleading.
The LPSTR value returned is a "fabricated" LPSTR and cannot be
considered a general-purpose string pointer. Consider the definition
of the MAKEINTATOM macro:
#define MAKEINTATOM(i) (LPSTR) ((DWORD)((WORD)(i)))
ATOM AddIntAtom(int iAtom)
{
LPSTR szAtom;
MessageBox(hWnd,
(szAtom=MAKEINTATOM(iAtom)),
"Adding Atom",
MB_OK);
return (AddAtom(szAtom));
}
ATOM AddIntAtom(int iAtom)
{
LPSTR szAtom;
char szBuf[10];
szAtom=MAKEINTATOM(iAtom);
sprintf(szBuf, "%d", LOWORD(szAtom)); /* Here's the trick */
MessageBox(hWnd,
szBuf,
"Adding Atom",
MB_OK);
return (AddAtom(szAtom));
}
In the above example, we converted the integer value contained in the
LOWORD of szAtom into a character string, then used this new character
string in the MessageBox() call.
sprintf (szBuf, "%d", iAtom);
MessageBox (hWnd, szBuf,....);
Additional query words: 3.00 3.10 3.50 4.00 win16sdk
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: March 2, 1999