CreateFile() On Comms Ports (API call from VB)
-
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 :)
-
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 :)