Solved

how can I get the list of the COM available ?

Posted on 2001-06-05
9
174 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
  • 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 65 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What are new names for Microsoft test frameworks once called Moles and Pex? 2 62
dialer.exe 4 64
String manipulation in Visual Basic 7 73
I could not set window to top 4 21
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

860 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