Determining Which COM Ports Are Present in Enhanced Mode

Last reviewed: February 15, 1996
Article ID: Q76280
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.1 and 3.0

SUMMARY

A problem with the communications driver causes a device contention message box to appear when a nonexistent port is opened in enhanced mode Windows using the OpenComm function. This article describes a method of avoiding this message box when using the communication API under enhanced mode Windows.

ENUMPORT.EXE is a file in the Software/Data Library that demonstrates the techniques detailed in this article.

Download ENUMPORT.EXE from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download ENUMPORT.EXE (size: 21744 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get ENUMPORT.EXE (size: 21744 bytes) 
    

MORE INFORMATION

Under standard or real mode, the OpenComm function can be used to successfully test for the presence of communications hardware by checking the return value. If the return value of the OpenComm function is IE_HARDWARE, it is safe to assume that the hardware is not present.

However, under enhanced mode Windows, calling the OpenComm function with a port ID that is not valid will cause the following message to appear on the screen:

   The COMx port is currently assigned to an MS-DOS-based application. Do
   you want to reassign the port to Windows?

This message is also be displayed if the port ID is valid; however, it is in use by another virtual machine.

To avoid this message in enhanced mode Windows, a communications application can call the API entry point of the virtual communications device (VCD) with a special function ID to determine the valid ports in the system.

The code fragment included below will fill a byte with a value that enumerates the valid COM ports:

VCD_Device_ID   equ     0Eh
lpAPI           dd      ?
bPortArray      db      ?

EnumeratePorts:
                xor     di, di
                mov     es, di
                mov     ax, 1684h
                mov     bx, VCD_Device_ID
                int     2Fh
                mov     ax, es
                or      ax, di
                jz      Enumerate_Failed

                ; VCD API is available... enumerate the ports

                mov     word ptr lpAPI, di
                mov     word ptr lpAPI+2, es

                mov     dx, 1           ; API for Get_Port_Array
                call    dword ptr lpAPI
                mov     bPortArray, al  ; returned in AL
                jmp     Enumerate_Exit

Enumerate_Failed:
                mov     bPortArray, 0

Enumerate_Exit:
                ret

After running this code fragment, the value in bPortArray will determine the valid ports. For example:

        bit 0   - COM1 (set if COM1 is available)
        bit 1   - COM2 (set if COM2 is available)
        ...
        bit 8   - COM7 (set if COM7 is available, not supported in
                        standard VCD)

A value of 3 indicates that both COM1 and COM2 are present in the system.


Additional reference words: 3.00 3.10 softlib ENUMPORT.ZIP
KBCategory: kbprg kbfile kbcode
KBSubcategory: KrCommapi


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: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.