win2000下的串口编程(200分)

  • 主题发起人 主题发起人 bobiy
  • 开始时间 开始时间
B

bobiy

Unregistered / Unconfirmed
GUEST, unregistred user!
var<br>&nbsp; lpdcb &nbsp; &nbsp;:Tdcb;<br>&nbsp; timeout &nbsp; :Tcommtimeouts;<br>&nbsp; sa :SECURITY_ATTRIBUTES;//win2000下加的<br>begin<br>&nbsp; hcom:=createfile(comname,generic_read or generic_write,0,@sa,open_existing,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file_flag_overlapped,0);<br><br>&nbsp; if hcom&lt;&gt;invalid_handle_value &nbsp;then<br>&nbsp; begin<br>&nbsp; &nbsp; setupcomm(hcom,4096,4096);<br>&nbsp; &nbsp; getcommstate(hcom,lpdcb);<br>&nbsp; &nbsp; lpdcb.baudrate:=9600;<br>&nbsp; &nbsp; lpdcb.bytesize:=8;<br>&nbsp; &nbsp; lpdcb.parity:=noparity;<br>&nbsp; &nbsp; setcommstate(hcom,lpdcb);<br>&nbsp; &nbsp; result:=true;<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; messagedlg('串口打开错误',mterror,[mbyes],0);<br>&nbsp; &nbsp; result:=false;<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br><br>&nbsp; timeout.readintervaltimeout:=10;<br>&nbsp; timeout.readtotaltimeoutmultiplier:=20;<br>&nbsp; timeout.readtotaltimeoutconstant:=30;<br>&nbsp; setcommtimeouts(hcom,timeout);<br><br>在win98下程序可以通过,在2000下根据winsdk的说明加入了sa :SECURITY_ATTRIBUTES;<br>结果 hcom=invalid_handle_value &nbsp;出错了!如果把sa改为PSecurityAttributes出错<br>提示为访问地址出错。<br><br>不知道各位有什么好的建议。谢谢大家了。<br><br>
 
下载spcomm控件<br>看它的原码<br>我就是这样做的
 
sa := nil;<br>再试试
 
lpSecurityAttributes<br><br>Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpSecurityAttributes is NULL, the handle cannot be inherited. <br><br>Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the object. If lpSecurityAttributes is NULL, the object gets a default security descriptor. The target file system must support security on files and directories for this parameter to have an effect on files.<br>Windows 95: The lpSecurityDescriptor member of the structure is ignored.<br><br>但是help是这么写的啊,难到2000和nt不同吗?
 
多人接受答案了。
 
后退
顶部