Solved

Visual Basic question

Posted on 1997-06-20
1
221 Views
Last Modified: 2013-11-25
I want to know how to access to the COM port with VB4.0 Standard Edition so without MSCOMM.
Which API I need ?
0
Comment
Question by:F1ISJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
dansari earned 0 total points
ID: 1427523
F1ISJ:
Here are some help pages from the Win32 SDK:

The comm device class consists of communications ports. You access these devices by using the Win32 file and communications functions.
The lineGetID and phoneGetID functions fill a VARSTRING structure, setting the dwStringFormat member to the STRINGFORMAT_ASCII value and appending a null-terminated string that specifies the name of the communication port (such as COM1). You use this port name in a call to the CreateFile function to open the communication device for the line or phone.

**********

The CreateFile function creates, opens, or truncates a file, pipe, communications resource, disk device, or console. It returns a handle that can be used to access the object. It can also open and return a handle to a directory.
HANDLE CreateFile(
 

    LPCTSTR  lpFileName,      // pointer to name of the file
    DWORD  dwDesiredAccess,      // access (read-write) mode
    DWORD  dwShareMode,      // share mode
    LPSECURITY_ATTRIBUTES  lpSecurityAttributes,      // pointer to security descriptor
    DWORD  dwCreationDistribution,      // how to create
    DWORD  dwFlagsAndAttributes,      // file attributes
    HANDLE  hTemplateFile       // handle to file with attributes to copy  
   );      
Parameters
lpFileName
Points to a null-terminated string that specifies the name of the file, pipe, communications resource, disk device, or console to create, open, or truncate.
If *lpFileName is a path, there is a default string size limit of MAX_PATH characters. This limit is related to how the CreateFile function parses paths.
Windows NT: You can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of CreateFile and prepending "\\?\" to the path. The "\\?\" tells the function to turn off path parsing. This lets you use paths that are nearly 32k Unicode characters long. You must use fully-qualified paths with this technique. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\tom_1\hotstuff\coolapps" is seen as "\\tom_1\hotstuff\coolapps".
dwDesiredAccess
Specifies the type of access to the file or other object. An application can obtain read access, write access, read-write access, or device query access. You can use the following flag constants to build a value for this parameter. Both GENERIC_READ and GENERIC_WRITE must be set to obtain read-write access:
 
Value      Meaning

0      Allows an application to query device attributes without actually accessing the device.
GENERIC_READ      Specifies read access to the file. Data can be read from the file and the file pointer can be moved.
GENERIC_WRITE      Specifies write access to the file. Data can be written to the file and the file pointer can be moved.
dwShareMode
Specifies how this file can be shared. This parameter must be some combination of the following values:
 
Value      Meaning

0      Prevents the file from being shared.
FILE_SHARE_READ      Other open operations can be performed on the file for read access. If the CreateFile function is opening the client end of a mailslot, this flag is specified.
FILE_SHARE_WRITE      Other open operations can be performed on the file for write access.
lpSecurityAttributes
Points to a SECURITY_ATTRIBUTES structure that specifies the security attributes for the file. The file system must support this parameter for it to have an effect.
dwCreationDistribution
Specifies which action to take on files that exist, and which action to take when files do not exist. For more information about this parameter, see the following Remarks section. This parameter must be one of the following values:
 
Value      Meaning

CREATE_NEW      Creates a new file. The function fails if the specified file already exists.
CREATE_ALWAYS      Creates a new file. The function overwrites the file if it exists.
OPEN_EXISTING      Opens the file. The function fails if the file does not exist.
      See the "Remarks" section, following, for a discussion of why you should use the OPEN_EXISTING flag if you are using the CreateFile function for a device, including the console.
OPEN_ALWAYS      Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDistribution were CREATE_NEW.
TRUNCATE_EXISTING      Opens the file. Once opened, the file is truncated so that its size is zero bytes. The calling process must open the file with at least GENERIC_WRITE access. The function fails if the file does not exist.
dwFlagsAndAttributes
Specifies the file attributes and flags for the file.
Any combination of the following attributes is acceptable, except all other file attributes override FILE_ATTRIBUTE_NORMAL.
 
Attribute      Meaning

FILE_ATTRIBUTE_ARCHIVE      The file is an archive file. Applications use this attribute to mark files for backup or removal.
FILE_ATTRIBUTE_COMPRESSED      The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories.
FILE_ATTRIBUTE_NORMAL      The file has no other attributes set. This attribute is valid only if used alone.
FILE_ATTRIBUTE_HIDDEN      The file is hidden. It is not to be included in an ordinary directory listing.
FILE_ATTRIBUTE_READONLY      The file is read only. Applications can read the file but cannot write to it or delete it.
FILE_ATTRIBUTE_SYSTEM      The file is part of or is used exclusively by the operating system.
Any combination of the following flags is acceptable.
 
Flag      Meaning


FILE_FLAG_WRITE_THROUGH      

      Instructs the operating system to write through any intermediate cache and go directly to the file. The operating system can still cache write operations, but cannot lazily flush them.

FILE_FLAG_OVERLAPPED      

      Instructs the operating system to initialize the file, so ReadFile, WriteFile, ConnectNamedPipe, and TransactNamedPipe operations that take a significant amount of time to process return ERROR_IO_PENDING. When the operation is finished, an event is set to the signaled state.
      When you specify FILE_FLAG_OVERLAPPED, the ReadFile and WriteFile functions must specify an OVERLAPPED structure. That is, when FILE_FLAG_OVERLAPPED is specified, an application must perform overlapped reading and writing.
      When FILE_FLAG_OVERLAPPED is specified, the operating system does not maintain the file pointer. The file position must be passed as part of the lpOverlapped parameter (pointing to an OVERLAPPED structure) to the ReadFile and WriteFile functions.
      This flag also enables more than one operation to be performed simultaneously with the handle (a simultaneous read and write operation, for example).

FILE_FLAG_NO_BUFFERING      

      Instructs the operating system to open the file with no intermediate buffering or caching. This can provide performance gains in some situations. An application must meet certain requirements when working with files opened with FILE_FLAG_NO_BUFFERING:7      File access must begin at offsets within the file that are integer multiples of the volume's sector size. 7      File access must be for numbers of bytes that are integer multiples of the volume's sector size. For example, if the sector size is 512 bytes, an application can request reads and writes of 512, 1024, or 2048 bytes, but not of 335, 981, or 7171 bytes. 7      Buffer addresses for read and write operations must be aligned on addresses in memory that are integer multiples of the volume's sector size. An application can determine a volume's sector size by calling the GetDiskFreeSpace function.

FILE_FLAG_RANDOM_ACCESS      

      Indicates that the file is accessed randomly. Windows uses this flag to optimize file caching.

FILE_FLAG_SEQUENTIAL_SCAN      

      Indicates that the file is to be accessed sequentially from beginning to end. Windows uses this flag to optimize file caching. If an application moves the file pointer for random access, optimum caching may not occur; however, correct operation is still guaranteed.
      Specifying this flag can increase performance for applications that read large files using sequential access. Performance gains can be even more noticeable for applications that read large files mostly sequentially, but occasionally skip over small ranges of bytes.

FILE_FLAG_DELETE_ON_CLOSE      

      Indicates that the operating system is to delete the file immediately after all of its handles have been closed.If you use this flag when you call CreateFile, then open the file again, and then close the handle for which you specified FILE_FLAG_DELETE_ON_CLOSE, the file will not be deleted until after you have closed the second and any other handle to the file.

FILE_FLAG_BACKUP_SEMANTICS      

      Windows NT only: Indicates that the file is being opened or created for a backup or restore operation. The operating system ensures that the calling process overrides file security checks, provided it has the necessary permission to do so. The relevant permissions are SE_BACKUP_NAME and SE_RESTORE_NAME.A Windows NT application can also set this flag to obtain a handle to a directory. A directory handle can be passed to some Win32 functions in place of a file handle.

FILE_FLAG_POSIX_SEMANTICS      

      Indicates that the file is to be accessed accoon moves the file pointer for random access, optimum caching may not occur; however, correct operation is still guaranteed.
      Specifying this flag can increase performance for applications that read large files using sequential access. Performance gains can be even more noticeable for applications that read large files mostly sequentially, but occasionally skip over small ranges of bytes.

FILE_FLAG_DELETE_ON_CLOSE      

      Indicates that the operating system is to delete the file immediately after all of its handles have been closed.If you use this flag when you call CreateFile, then open the file again, and then close the handle for which you specified FILE_FLAG_DELETE_ON_CLOSE, the file will not be deleted until after you have closed the second and any other handle to the file.

FILE_FLAG_BACKUP_SEMANTICS      

      Windows NT only: Indicates that the file is being opened or created for a backup or restore operation. The operating system ensures that the calling process overrides file security checks, provided it has the necessary permission to do so. The relevant permissions are SE_BACKUP_NAME and SE_RESTORE_NAME.A Windows NT application can also set this flag to obtain a handle to a directory. A directory handle can be passed to some Win32 functions in place of a file handle.

FILE_FLAG_POSIX_SEMANTICS      

      Indicates that the file is to be accessed accorites the file if it exists.
OPEN_EXISTING      Opens the file. The function fails if the file does not exist.
      See the "Remarks" section, following, for a discussion of why you should use the OPEN_EXISTING flag if you are using the CreateFile function for a device, including the console.
OPEN_ALWAYS      Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDistribution were CREATE_NEW.
TRUNCATE_EXISTING      Opens the file. Once opened, the file is truncated so that its size is zero bytes. The calling process must open thon moves the file pointer for random access, optimum caching may not occur; however, correct operation is still guaranteed.
      Specifying this flag can increase performance for applications that read large files using sequential access. Performance gains can be even more noticeable for applications that read large files mostly sequentially, but occasionally skip over small ranges of bytes.

FILE_FLAG_DELETE_ON_CLOSE      

      Indicates that the operating system is to delete the file immediately after all of its handles have been closed.If you use this flag when you call CreateFile, then open the file again, and then close the handle for which you specified FILE_FLAG_DELETE_ON_CLOSE, the file will not be deleted until after you have closed the second and any other handle to the file.

FILE_FLAG_BACKUP_SEMANTICS      

      Windows NT only: Indicates that the file is being opened or created for a backup or restore operation. The operating system ensures that the calling process overrides file security checks, provided it has the necessary permission to do so. The relevant permissions are SE_BACKUP_NAME and SE_RESTORE_NAME.A Windows NT application can also set this flag to obtain a handle to a directory. A directory handle can be passed to some Win32 functions in place of a file handle.

FILE_FLAG_POSIX_SEMANTICS      

      Indicates that the file is to be accessed accorites the file if it exists.
OPEN_EXISTING      Opens the file. The function fails if the file does not exist.
      See the "Remarks" section, following, for a discussion of why you should use the OPEN_EXISTING flag if you are using the CreateFile function for a device, including the console.
OPEN_ALWAYS      Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDistribution were CREATE_NEW.
TRUNCATE_EXISTING      Opens the file. Once opened, the file is truncated so that its size is zero bytes. The calling process must open the file with at least GENERIC_WRITE access. The function fails if the file does not exist.
dwFlagsAndAttributes
Specifies the file attributes and flags for the file.
Any combination of the following attributes is acceptable, except all other file attributes override FILE_ATTRIBUTE_NORMAL.
 
Attribute      Meaning

FILE_ATTRIBUTE_ARCHIVE      The file is an archive file. Applications use this attribute to mark files for backup or removal.
FILE_ATTRIBUTE_COMPRESSED      The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories.
FILE_ATTRIBUTE_NORMAL      The file has no other attributes set. This attribute is valid only if used alone.
FILE_ATTRIBUx5      
@
@h?

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question