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;
发表评论 取消回复