我是靠谱客的博主 痴情店员,这篇文章主要介绍Delphi CreateFile 用法,现在分享给大家,希望可以做个参考。

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 attributes
  DWORD dwCreationDistribution, // how to create
  DWORD dwFlagsAndAttributes, // file attributes
  HANDLE hTemplateFile // handle to file with attributes to copy
  );
  lpFileName: 指明串口制备,例:COM1,COM2
  dwDesiredAccess: 指明串口存取方式,例:GENERIC_READ|GENERIC_WRITE
  dwShareMode: 指明串口共享方式
  lpSecurityAttributes: 指明串口的安全属性结构,NULL为缺省安全属性
  dwCreateionDistribution: 必须为OPEN_EXISTIN
  dwFlagAndAttributes: 对串口唯一有意义的是FILE_FLAG_OVERLAPPED
  hTemplateFile: 必须为NULL


例子:

m_hComm := CreateFile(                    //创建文件(串口),取得操作句柄
PChar(sCommPort),                        //文件名称
//'\.COM10',
GENERIC_READ or GENERIC_WRITE,         //操作方式(读或写)
dwShareMode,                           //共享方式
nil,                                   //SD
OPEN_EXISTING,                         //文件创建方法
FILE_ATTRIBUTE_NORMAL,                 //文件属性
0);                                    //handle to template file

if( m_hComm = INVALID_HANDLE_VALUE ) then     //串口打开失败
begin
;
end;


最后

以上就是痴情店员最近收集整理的关于Delphi CreateFile 用法的全部内容,更多相关Delphi内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(140)

评论列表共有 0 条评论

立即
投稿
返回
顶部