BUG: GetTextExtentPoint Fails in App Based on Windows/Win32sID: Q147647
|
GetTextExtentPoint fails when all of the following conditions are present:
GetTextExtentPoint - Invalid string
As stated earlier, this problem occurs only when the allocated size of the
string is an exact multiple of 32 bytes.
This is a bug in Microsoft Windows 3.1 that causes ramifications in a
16-bit application running under Windows 3.1. A 16-bit application running
under Windows NT 3.51 will have the same problem, but it will run without
any problems under Windows 95.
This bug is not specific to Win32s. However, because Win32s runs under the
Windows environment, a 32-bit application running under Windows 3.1 by way
of Win32s will also exhibit this problem. However, a 32-bit application
running under Windows NT or Windows 95 will not exhibit this problem.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
Note that GetTextExtentPoint() will succeed if you pass a string constant
that has a size that is a multiple of 32. For example, the following will
work:
GetTextExtentPoint(hDC, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 32, &size);
HGLOBAL hMem;
HDC hDC;
SIZE size;
int blksize, i;
char szMsg[256];
LPSTR lpBuf;
blksize=32;
#ifdef WIN32
SetLastError(0);
#endif
hDC = GetDC(hWnd);
hMem = GlobalAlloc(GHND, blksize);
lpBuf = (LPSTR) GlobalLock(hMem);
for (i=0; i<blksize; i++)
lpBuf[i] = 't';
if (!GetTextExtentPoint(hDC, lpBuf, blksize, &size))
{
#ifdef WIN32
wsprintf(szMsg, "GetTextExtentPoint Error %d\r\n", GetLastError());
#else
wsprintf(szMsg, "GetTextExtentPoint Error\r\n);
#endif
MessageBox(NULL, szMsg, "Test", MB_OK);
}
GlobalUnlock(hMem);
#ifdef WIN32
SetLastError(0);
#endif
hMem = GlobalReAlloc(hMem, 2*blksize, GMEM_ZEROINIT);
lpBuf = (LPSTR) GlobalLock(hMem);
for (i=0; i<blksize; i++)
lpBuf[blksize+i] = 'T';
if (!GetTextExtentPoint(hDC, lpBuf, 2*blksize, &size))
{
#ifdef WIN32
wsprintf(szMsg, "GetTextExtentPoint Error %d\r\n", GetLastError());
#else
wsprintf(szMsg, "GetTextExtentPoint Error \r\n");
#endif
MessageBox(NULL, szMsg, "Test", MB_OK);
}
GlobalUnlock(hMem);
if (hMem) GlobalFree(hMem);
Additional query words: win32s gdi 1.30c 4.00 3.10 3.51
Keywords : kbGDI kbWin32s
Version : 1.30c 4.00 3.10 | 3.51
Platform : NT WINDOWS
Issue type :
Last Reviewed: March 12, 1999