Solved

how can I get the list of the COM available ?

Posted on 2001-06-05
9
170 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
 

Author Comment

by:kobibass
ID: 6156240
But I need to get them into MFC combo box list.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now