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. Access non-exposed port.

Access non-exposed port.

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiowindows-adminquestion
2 Posts 1 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.
  • C Offline
    C Offline
    Comp_Users
    wrote on last edited by
    #1

    Hi, I am working on VS 2005 on Vista platform. I have an mobile data card which exposes an Modem Port and this port appears as an device entry under "Modems" in the Device Manager. In addition to this, the device has another port which i figured out by scanning through the registry and this port does not appear in the device manager. This port appears in the list of available ports displayed by HyperTerminal and also in PortMon and I can connect and talk to the device via HyperTerminal. But in my application when I try to do an CreateFile with that port name, the call fails with GetLastError() returning 2.

            TCHAR szPortName\[MAX\_PATH\]=\_T("");
    	\_tcscpy(szPortName, \_T("\\\\\\\\.\\\\"));
    	\_tcscat(szPortName, \_T("COM6:");	//assume the non-exposed port is COM6.
    
    	HANDLE hDeviceFile = CreateFile(szPortName,
    		GENERIC\_READ | GENERIC\_WRITE,
    		0,
    		NULL,
    		OPEN\_EXISTING,
    		0,
    		NULL);
    	DWORD dwReturn = GetLastError();
    

    Is there something wrong in the CreateFile() function call above. Or is it that Vista allows only ports that are expose/displayed in the Device Manager for an Device to be used by an application?

    C 1 Reply Last reply
    0
    • C Comp_Users

      Hi, I am working on VS 2005 on Vista platform. I have an mobile data card which exposes an Modem Port and this port appears as an device entry under "Modems" in the Device Manager. In addition to this, the device has another port which i figured out by scanning through the registry and this port does not appear in the device manager. This port appears in the list of available ports displayed by HyperTerminal and also in PortMon and I can connect and talk to the device via HyperTerminal. But in my application when I try to do an CreateFile with that port name, the call fails with GetLastError() returning 2.

              TCHAR szPortName\[MAX\_PATH\]=\_T("");
      	\_tcscpy(szPortName, \_T("\\\\\\\\.\\\\"));
      	\_tcscat(szPortName, \_T("COM6:");	//assume the non-exposed port is COM6.
      
      	HANDLE hDeviceFile = CreateFile(szPortName,
      		GENERIC\_READ | GENERIC\_WRITE,
      		0,
      		NULL,
      		OPEN\_EXISTING,
      		0,
      		NULL);
      	DWORD dwReturn = GetLastError();
      

      Is there something wrong in the CreateFile() function call above. Or is it that Vista allows only ports that are expose/displayed in the Device Manager for an Device to be used by an application?

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

      Found the problem. I was specifying Port Name as _T("COM6:") while the correct was is _T("COM6") i.e, without the colon at the end.

      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