INFO: GetCommProperties Returns Error 122 If Called from TAPI Ap

Last reviewed: September 30, 1997
Article ID: Q162136
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows NT version 4.0

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.