Article ID: 162136
Article Last Modified on 11/21/2006
DWORD dwError;
COMMPROP commprop;
memset(&commprop, 0, sizeof(COMMPROP));
if(!GetCommProperties(hCommHandle, &commprop))
{
dwError = GetLastError();
}
The same code fails under Windows NT, Windows 2000, and Window XP and dwError will be set to 122 (ERROR_INSUFFICIENT_BUFFER).
DWORD dwSize;
COMMPROP *commprop;
DWORD dwError;
dwSize = sizeof(COMMPROP) + sizeof(MODEMDEVCAPS) ;
commprop = (COMMPROP *)malloc(dwSize);
memset(commprop, 0, dwSize);
commprop->wPacketLength = dwSize;
commprop->dwProvSubType = PST_MODEM;
commprop->dwProvSpec1 = COMMPROP_INITIALIZED;
if(!GetCommProperties(hNewCommFile, commprop))
{
dwError = GetLastError();
}
The following example demonstrates a method that works for both platforms.
The code below calls GetCommProperties first with the Windows 95 style
structure allocation. If that fails, it calls GetCommProperties with
Windows NT, Windows 2000, and Windows XP style structure allocation.
COMMTIMEOUTS commtimeouts;
DCB dcb;
DWORD dwSize;
COMMPROP *commprop;
DWORD fdwEvtMask;
DWORD dwError;
dwSize = sizeof(COMMPROP);
commprop = (COMMPROP *)malloc(dwSize);
memset(commprop, 0, dwSize);
GetCommState(hComm, &dcb);
if(!GetCommProperties(hComm, commprop))
{
if(GetLastError()==122)
{
free(commprop);
dwSize = sizeof(COMMPROP) + sizeof(MODEMDEVCAPS);
commprop = (COMMPROP *)malloc(dwSize);
memset(commprop, 0, dwSize);
commprop->wPacketLength = dwSize;
commprop->dwProvSubType = PST_MODEM;
commprop->dwProvSpec1 = COMMPROP_INITIALIZED;
if(!GetCommProperties(hComm, commprop))
{
dwError = GetLastError();
}
}
}
free(commprop);
Additional query words: tapi commapi unimodem ntbug nt40 commbug tapibug
Keywords: kbapi kbinfo kbkernbase kbtapi KB162136