Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:27:58+00:00 2026-06-08T23:27:58+00:00

I am using a COM port in C++. I can not open COM ports

  • 0

I am using a COM port in C++. I can not open COM ports with a higher number than 9, for example 10. This is function used for COM port detection:

WCHAR port_name[7];
WCHAR num_port[4];        

for (i=1; i<256; i++)
{
    bool bSuccess = false;

    wcscpy(port_name,L"COM");
    wcscat(port_name,_itow(i,num_port,10));

    HANDLE hPort;

    //Try to open the port
    hPort = CreateFile(L"COM10", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
    //hPort = CreateFile(port_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);

    if (hPort == INVALID_HANDLE_VALUE)
    {
        DWORD dwError = GetLastError();

        //Check to see if the error was because some other application had the port open
        if (dwError == ERROR_ACCESS_DENIED)
        {
            bSuccess = TRUE;
            j=j+1;  
        }
    }
    else   //The port was opened successfully
    {            
        bSuccess = TRUE;
        j=j+1;

        CloseHandle(hPort);   //closing the port
    }

    if (bSuccess)array_ports[j]=i;

}

I can not understand why for example COM10, throws FFFFFFFF back to HANDLE hPort.

hPort = CreateFile(L"COM10", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);

COM9, COM8, COM7, etc. works fine,

hPort = CreateFile(L"COM9", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);

It there a solution for this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:27:59+00:00Added an answer on June 8, 2026 at 11:27 pm

    It is a bug and the resolution is to use the string

    \\.\COM10
    
    hPort = CreateFile("\\\\.\\COM10", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
    

    check this article.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can the Windows COM port be used by two programs running on the same
I created an applet using RXTXComm.jar to read values from a COM port. When
I'm using the following config: ActionMailer::Base.smtp_settings = { :address => smtp.gmail.com, :port => 587,
I am using a com DLL in the following manner: #Region API Function <DllImportAttribute(abc.dll,
I built a project as descripted in this URL: http://msdn.microsoft.com/en-us/library/ms734784.aspx I used the app.config
While connecting my Com-port using matlab, many a times(4 out of 5) I get
php.ini [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = ssl://smtp.gmail.com ; http://php.net/smtp-port
I have an application that reads data from a com port using javax.comm. The
When using COM boolean values are to be passed as VARIANT_BOOL which is declared
I have defined the following class using COM to use the IGroupPolicyObject using C#.NET:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.