请问如何对LPT1、COM1等进行访问

szch 2003-02-17 09:49:05
加精
请问如何对LPT1、COM1等进行访问
FileOpen(1, "LPT1", OpenMode.Output)
提示调用 CreateFile,然后使用采用 OS 句柄作为 IntPtr 的 FileStream 构造函数。
如何调用 CreateFile?
...全文
166 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
szch 2003-02-19
  • 打赏
  • 举报
回复
谢谢了!
Montaque 2003-02-18
  • 打赏
  • 举报
回复
CreateFile是一个API函数,很多通讯的程序都用到,
szch 2003-02-18
  • 打赏
  • 举报
回复
Montaque(Rainman)兄,是否没有?
那我只好结贴了。
Montaque 2003-02-17
  • 打赏
  • 举报
回复
CreateFile是一个API,比如这样写:

Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000

Const OPEN_EXISTING = 3

Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As IntPtr

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iHandle As IntPtr
iHandle = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
If (iHandle.ToInt32 = -1) Then
MsgBox("can not open port")
Else
MsgBox("Open Succes!")
Dim fs As New FileStream(iHandle, FileAccess.ReadWrite)
Dim sr As New StreamReader(fs) '读数据
Dim sw As New StreamWriter(fs) '些数据
End If
End Sub
szch 2003-02-17
  • 打赏
  • 举报
回复
Montaque(Rainman)兄
CreateFile对应的类还是找不到。
Montaque 2003-02-17
  • 打赏
  • 举报
回复
system.io下面有很多文件操作的类,比如filestream等。
szch 2003-02-17
  • 打赏
  • 举报
回复
Montaque(Rainman)兄,谢谢了!
再想问一下,CreateFile在VB.NET中有无对应的类?

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧