Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how can I get the list of the COM available ?

Posted on 2001-06-05
9
Medium Priority
?
189 Views
Last Modified: 2013-11-25
Hello experts.


Is there a way to get the list of the COM ports available for use?
0
Comment
Question by:kobibass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6156163
The easiest way is to open them:

CStringList m_portlist;

//...

    //  create list of available comm ports

    char    acPort  [   5]  =   "COM1";

    for (   UCHAR   uc  =   0;  uc  <   8;  uc++)
        {
            HANDLE  hPort   =   INVALID_HANDLE_VALUE;

            acPort  [   3]  +=  uc;

            hPort   =   CreateFile  (   acPort,
                                        GENERIC_READ | GENERIC_WRITE,
                                        0,
                                        0,
                                        OPEN_EXISTING,
                                        0,
                                        0
                                    );

            if  (   INVALID_HANDLE_VALUE    !=  hPort)
                {
                    CString*    pstr    =   new CString (   acPort);

                    m_portlist.AddTail  (   pstr);

                    CloseHandle (   hPort);
                }

        }
0
 

Author Comment

by:kobibass
ID: 6156180
But I need to get them into MFC combo box list.
0
 
LVL 86

Accepted Solution

by:
jkr earned 260 total points
ID: 6156221
Well, your question was about how to get the available ports. If you want to add them to a ComboBox, just use

   //  create list of available comm ports

   char    acPort  [   5]  =   "COM1";

   for (   UCHAR   uc  =   0;  uc  <   8;  uc++)
       {
           HANDLE  hPort   =   INVALID_HANDLE_VALUE;

           acPort  [   3]  +=  uc;

           hPort   =   CreateFile  (   acPort,
                                       GENERIC_READ | GENERIC_WRITE,
                                       0,
                                       0,
                                       OPEN_EXISTING,
                                       0,
                                       0
                                   );

           if  (   INVALID_HANDLE_VALUE    !=  hPort)
               {
                   CString*    pstr    =   new CString (   acPort);

                   m_myPortComboBox.AddTail  (   pstr);

                   CloseHandle (   hPort);
               }

       }

 
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:kobibass
ID: 6156240
But I need to get them into MFC combo box list.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6156269
>>But I need to get them into MFC combo box list.

Where's the problem? Just use

m_myPortComboBox.AddString( pstr);


0
 

Author Comment

by:kobibass
ID: 6156679
how is m_myPortComboBox defined? (AddString and AddTail working on class)
0
 
LVL 86

Expert Comment

by:jkr
ID: 6156691
CComboBox m_myPortComboBox;
0
 

Author Comment

by:kobibass
ID: 6158906
jkr hello,

In the rc file there is a declaration of COMBOBOX IDC_PORTCOM. I need to relate the list to this combobox.

how can I do this?

thanks for yor help,

kobi.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6160801
Well, in this case (without knowing your code), the easiest way is to use

SendDlgItemMessage(
 hWnd, // your window's handle
 IDC_PORTCOM,
 CB_ADDSTRING,
 0,
 (LPARAM) ( ( LPCTSTR) *pstr)
);


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question