I have used the function below in a standard C program and an MFC
application which runs on Microsoft Windows 9x, NT and Windows 2000
platforms without problems.
However, when I use this function in an ATL control it works fine under
Windows 98 and Windows NT v4 but fails on Windows 2000. As it is straight
from Chris Sells TAPI book I am a bit perplexed.
Has anyone had this experience? Can anyone see why this might happen.
Under Windows 2000, the second time lineGetDevCaps is called, it fails.
Any feedback would be much appreciated.
If I just do a malloc(<sufficient memory>) it works OK. But obviously the
dynamic allocation in the code below is much more efficient.
Here is the code:
void CPhone::MyGetLineDevCaps(HLINEAPP hLineApp, DWORD nApiVersion, DWORD
nLineID, LINEDEVCAPS **ppd)
DWORD dwNeededSize = sizeof(LINEDEVCAPS);
LONG tr = 0;
// Get some more memory if we don't have enough
if( !*ppd || (*ppd)->dwTotalSize < dwNeededSize )
*ppd = (LPLINEDEVCAPS)::realloc(*ppd,
if( *ppd )
(*ppd)->dwTotalSize = dwNeededSize;
// return LINEERR_NOMEM;
// Fill in the buffer
tr = lineGetDevCaps(hLineApp, nLineID, nApiVersion, 0, *ppd);
// Check how much memory we need
// (some TSPs succeed even if the
// data size is too small)
if( tr == LINEERR_STRUCTURETOOSMALL ||
(tr == 0 &&
(*ppd)->dwTotalSize < (*ppd)->dwNeededSize) )
dwNeededSize = (*ppd)->dwNeededSize;
tr = LINEERR_STRUCTURETOOSMALL;
while( tr == LINEERR_STRUCTURETOOSMALL );
// return S_OK;