INFO: GetCommProperties Returns Error 122 If Called from TAPI Ap

ID: Q162136

The information in this article applies to:

SUMMARY

Under Windows NT 4.0, GetCommProperties API call fails when called using a communication handle obtained from the TAPI lineGetID API if COMMPROP structure is not properly initialized.

Under Windows 95, UNIMODEM expects the structure to be zero initialized.

This behavior is specific to UNIMODEM as a TAPI Service Provider.

MORE INFORMATION

Under Windows 95's UNIMODEM, GetCommProperties succeeds when COMMPROP is allocated and zero initialized as follows:

   DWORD dwError;
   COMMPROP commprop;

   memset(&commprop, 0, sizeof(COMMPROP));
   if(!GetCommProperties(hCommHandle, &commprop))
   {
     dwError = GetLastError();
   }

The same code fails under Windows NT and dwError will be set to 122 (ERROR_INSUFFICIENT_BUFFER).

This occurs when UNIMODEM tries to append provider specific information to the end of COMMPROP in a form of MODEMDEVCAPS. To work around this, you need to allocate space for MODEMDEVCAPS structure after COMMPROP. You also need to set the appropriate member variable in COMMPROP so UNIMODEM knows that the structure has been allocated to the proper size. The following code sample demonstrates this process:

   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 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 kbKernBase kbTAPI Tapi kbGrpKernBase 
Version           : WINDOWS NT:4.0;
Platform          : NT WINDOWS
Issue type        : kbinfo

Last Reviewed: August 6, 1998