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. Visual Basic
  4. CreateFile() On Comms Ports (API call from VB)

CreateFile() On Comms Ports (API call from VB)

Scheduled Pinned Locked Moved Visual Basic
cssjsonhelpquestion
2 Posts 2 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.
  • J Offline
    J Offline
    Jason Teagle
    wrote on last edited by
    #1

    In 16-bit days I swapped from using the VB comms control to raw API (OpenComm(), ReadComm() and WriteComm() ) because we found that the comms control was less than reliable on Pentiums as they became available. That code worked fine. Now I'm trying to port that VB code to 32-bit. I have changed to using CreateFile(), ReadFile() and WriteFile() accordingly. However, despite copying the CreateFile() call from a VC program that I know works, and despite getting the correct API declaration from the APILOAD program, CreateFile() is not working. It returns -1 as the handle. I called GetLastError() immediately after this, but guess what... it returned 0. Very helpful. Here is how I'm trying to do it: hCommHandle = CreateFile( "COM1", GENERIC_READ + GENERIC_WRITE, ' Was GENERIC_READ|GENERIC_WRITE in VC. 0&, ' Share mode, it's a Long. 0&, ' Was null in VC - it's a Long. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&, ' Was null in VC - it's a Long. ) where GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING and FILE_ATTRIBUTE_NORMAL are all defined as Long constants as per the API. Can anyone help? I can guarantee the port is not opened elsewhere :)

    L 1 Reply Last reply
    0
    • J Jason Teagle

      In 16-bit days I swapped from using the VB comms control to raw API (OpenComm(), ReadComm() and WriteComm() ) because we found that the comms control was less than reliable on Pentiums as they became available. That code worked fine. Now I'm trying to port that VB code to 32-bit. I have changed to using CreateFile(), ReadFile() and WriteFile() accordingly. However, despite copying the CreateFile() call from a VC program that I know works, and despite getting the correct API declaration from the APILOAD program, CreateFile() is not working. It returns -1 as the handle. I called GetLastError() immediately after this, but guess what... it returned 0. Very helpful. Here is how I'm trying to do it: hCommHandle = CreateFile( "COM1", GENERIC_READ + GENERIC_WRITE, ' Was GENERIC_READ|GENERIC_WRITE in VC. 0&, ' Share mode, it's a Long. 0&, ' Was null in VC - it's a Long. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&, ' Was null in VC - it's a Long. ) where GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING and FILE_ATTRIBUTE_NORMAL are all defined as Long constants as per the API. Can anyone help? I can guarantee the port is not opened elsewhere :)

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

      lh = CreateFile("\\.\COM" & m_CommPort, GENERIC_READ Or GENERIC_WRITE, ByVal 0, ByVal 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0) :cool:

      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