Solved

how can I get the list of the COM available ?

Posted on 2001-06-05
9
180 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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…

705 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