Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ Open the COM Port on Windows CE Device

C++ Open the COM Port on Windows CE Device

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++com
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    baranils
    wrote on last edited by
    #1

    Hello I'm trying to open the COM Port on a Windows CE Device in C++ but without any success I'm sure that the port exist and available becaus I can use it from cSharp To do it with C++ I'm trying to use the CreateFile method The first issue was that CreateFile needs a LPCWSTR And as it is a long time that I did'nt work with C++ in Windows I had to find ho to assign a LPCWSTR Pointer So here is my attempt But it give an Error 2 during execution NB : I've also tryed different declaration of the Com port but with the same bad result

    wchar_t tt[]=L"COM5";
    wchar_t tt[]=L"COM5\0";
    wchar_t tt[]=L"COM5:";
    wchar_t tt[]=L"COM5:\0";}

    I can't believe that there is no way to open the Com port on Win CE in cSharp Thanks for any help

    wchar_t tt[]=L"COM5";
    int len=0;
    int result=0;
    char *buffer;
    DWORD dw;

    hComm = CreateFile( tt,
    GENERIC_READ | GENERIC_WRITE,
    0,
    0,
    OPEN_EXISTING,
    NULL,
    NULL);
    if (hComm == INVALID_HANDLE_VALUE)
    {
    dw=GetLastError();
    }

    C 1 Reply Last reply
    0
    • B baranils

      Hello I'm trying to open the COM Port on a Windows CE Device in C++ but without any success I'm sure that the port exist and available becaus I can use it from cSharp To do it with C++ I'm trying to use the CreateFile method The first issue was that CreateFile needs a LPCWSTR And as it is a long time that I did'nt work with C++ in Windows I had to find ho to assign a LPCWSTR Pointer So here is my attempt But it give an Error 2 during execution NB : I've also tryed different declaration of the Com port but with the same bad result

      wchar_t tt[]=L"COM5";
      wchar_t tt[]=L"COM5\0";
      wchar_t tt[]=L"COM5:";
      wchar_t tt[]=L"COM5:\0";}

      I can't believe that there is no way to open the Com port on Win CE in cSharp Thanks for any help

      wchar_t tt[]=L"COM5";
      int len=0;
      int result=0;
      char *buffer;
      DWORD dw;

      hComm = CreateFile( tt,
      GENERIC_READ | GENERIC_WRITE,
      0,
      0,
      OPEN_EXISTING,
      NULL,
      NULL);
      if (hComm == INVALID_HANDLE_VALUE)
      {
      dw=GetLastError();
      }

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      As far as I know, CreateFile's first argument must be a LPCTSTR.

      THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

      B 1 Reply Last reply
      0
      • C CPallini

        As far as I know, CreateFile's first argument must be a LPCTSTR.

        THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

        B Offline
        B Offline
        baranils
        wrote on last edited by
        #3

        Great ! You help me a lot 1- It is LPCTSTR indeed 2- The column is required This is working

        LPCTSTR portname = L"COM5:";

        int len=0;
        int result=0;
        char *buffer;
        DWORD dw;

        hComm = CreateFile( portname,
        GENERIC_READ | GENERIC_WRITE,
        0,
        NULL,
        OPEN_EXISTING,
        NULL,
        NULL);
        if (hComm == INVALID_HANDLE_VALUE)
        {
        dw=GetLastError();
        int uu=5;
        }

        C 1 Reply Last reply
        0
        • B baranils

          Great ! You help me a lot 1- It is LPCTSTR indeed 2- The column is required This is working

          LPCTSTR portname = L"COM5:";

          int len=0;
          int result=0;
          char *buffer;
          DWORD dw;

          hComm = CreateFile( portname,
          GENERIC_READ | GENERIC_WRITE,
          0,
          NULL,
          OPEN_EXISTING,
          NULL,
          NULL);
          if (hComm == INVALID_HANDLE_VALUE)
          {
          dw=GetLastError();
          int uu=5;
          }

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          The correct way to set the LPCTSTR is:

          LPCTSRT portname = _T("COM5:");

          As far as I know, the column is NOT required. By the way, you are welcome.

          THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

          L 1 Reply Last reply
          0
          • C CPallini

            The correct way to set the LPCTSTR is:

            LPCTSRT portname = _T("COM5:");

            As far as I know, the column is NOT required. By the way, you are welcome.

            THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Hi,

            CPallini wrote:

            As far as I know, the column is NOT required.

            It is required. Alternatively the full device namespace path can be used: "\\\\.\\COM1" Best Wishes, -David Delaune

            C 1 Reply Last reply
            0
            • L Lost User

              Hi,

              CPallini wrote:

              As far as I know, the column is NOT required.

              It is required. Alternatively the full device namespace path can be used: "\\\\.\\COM1" Best Wishes, -David Delaune

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              Randor wrote:

              It is required

              Is it a CE thing or this very MSDN example[^] is wrong?

              THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

              L 1 Reply Last reply
              0
              • C CPallini

                Randor wrote:

                It is required

                Is it a CE thing or this very MSDN example[^] is wrong?

                THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

                L Offline
                L Offline
                leon de boer
                wrote on last edited by
                #7

                It is quite specific under CE http://msdn.microsoft.com/en-us/library/aa517318.aspx[^] Could not be more clear => When lpFileName points to a COM port to open, you must include a colon after the name. For example, specify COM1: to open that port. When using IrCOMM, specify COM3:.

                In vino veritas

                C 1 Reply Last reply
                0
                • L leon de boer

                  It is quite specific under CE http://msdn.microsoft.com/en-us/library/aa517318.aspx[^] Could not be more clear => When lpFileName points to a COM port to open, you must include a colon after the name. For example, specify COM1: to open that port. When using IrCOMM, specify COM3:.

                  In vino veritas

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #8

                  OK, got it, thank you very much. By the way: Microsoft, oh my God! :-)

                  THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups