Solved

how can I get the list of the COM available ?

Posted on 2001-06-05
9
169 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
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…

760 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

18 Experts available now in Live!

Get 1:1 Help Now