Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
5Activity
0 of .
Results for:
No results containing your search query
P. 1
Giới thiệu các hàm API và hàm Visual C++ quan trọng sử dụng trong việc lập trình truyền thông nối tiếp

Giới thiệu các hàm API và hàm Visual C++ quan trọng sử dụng trong việc lập trình truyền thông nối tiếp

Ratings: (0)|Views: 351 |Likes:
Published by api-19851635

More info:

Published by: api-19851635 on Dec 01, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

GI\u1edaI HI\u1ec6U C\u00c1C H\u00c0M API V\u00c0 H\u00c0M VISUAL C++ QUAN TR\u1eccNG S\u1eec
D\u1ee4NG TRONG VI\u1ec6C L\u1eacP TR\u00ccNH TRUY\u1ec0N TH\u00d4NG N\u1ed0I TI\u1ebeP
1. H\u00e0mCre ate File ():
Ch\u1ee9c n\u0103ng: T\u1ea1o m\u1edf hay c\u1eaft b\u1edbt t\u1eadp tin, c\u1ed5ng COM, thi\u1ebft b\u1ecb, d\u1ecbch v\u1ee5, hay
b\u00e0n \u0111i\u1ec1u khi\u1ec3n. M\u1ed9t handle \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 \u0111\u1ec3 truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng.

HANDLE CreateFile(
LPCTSTR lpFileName, //t\u00ean file
DWORD dwDesiredAccess, //ph\u01b0\u01a1ng th\u1ee9c truy c\u1eadp
DWORD dwShareMode, //ch\u1ebf \u0111\u1ed9 chia s\u1ebb
LPSECURITY_ATTRIBUTES lpSecurityAttributes, //thu\u1ed9c t\u00ednh b\u1ea3o m\u1eadt
DWORD dwCreationDispostion, //s\u1ef1 ki\u1ec7n x\u1ea3y ra khi t\u1ea1o file
DWORD dwFlagsAndAttributes, //c\u1edd thu\u1ed9c t\u00ednh file
HANDLE hTemplateFile
);
C\u00e1c tham s\u1ed1

lpFileName
[v\u00e0o] Chu\u1ed7i kh\u00e1c r\u1ed7ng ch\u1ee9a t\u00ean c\u1ee7a \u0111\u1ed1i t\u01b0\u1ee3ng, nh\u01b0 file, c\u1ed5ng COM, thi\u1ebft b\u1ecb
\u0111\u0129a, ho\u1eb7c b\u00e0n \u0111i\u1ec1u khi\u1ec3n, \u0111\u1ec3 t\u1ea1o hay m\u1edf.

KhilpFileName ch\u1ec9 \u0111\u1ebfn m\u1ed9t c\u1ed5ng c\u1ea7n m\u1edf, b\u1ea1n ph\u1ea3i th\u00eam d\u1ea5u \u2018:\u2019 d\u1eb1ng sau t\u00ean. Th\u00ed d\u1ee5 ch\u1ec9 \u0111\u1ecbnh COM1: \u0111\u1ec3 m\u1edf c\u1ed5ng COM1. Khi s\u1eed d\u1ee5ng IrCOMM, ch\u1ec9 \u0111\u1ecbnh COM3:.

dwDesiredAccess

[v\u00e0o] Ph\u01b0\u01a1ng th\u1ee9c truy c\u1eadp \u0111\u1ed1i t\u01b0\u1ee3ng. M\u1ed9t \u1ee9ng d\u1ee5ng c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n truy c\u1eadp ch\u1ec9 \u0111\u1ecdc (read-only), ch\u1ec9 ghi (write-only), \u0111\u1ecdc/ghi, hay truy v\u1ea5n thi\u1ebft b\u1ecb. B\u1ea3ng sau m\u00f4 t\u1ea3 c\u00e1c gi\u00e1 tr\u1ecb c\u00f3 th\u1ec3 c\u1ee7adwDes ir edAcces s.

Gi\u00e1 tr\u1ecb
M\u00f4 t\u1ea3
0

X\u00e1c \u0111\u1ecbnh truy v\u1ea5n \u0111\u1ed1i t\u01b0\u1ee3ng. M\u1ed9t \u1ee9ng d\u1ee5ng c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n truy v\u1ea5n thu\u1ed9c t\u00ednh \u0111\u1ed1i t\u01b0\u1ee3ng m\u00e0 kh\u00f4ng truy c\u1eadp v\u00e0o thi\u1ebft b\u1ecb.

GENERIC_READ Ch\u1ec9 \u0111\u1ecbnh ph\u01b0\u01a1ng th\u1ee9c cho ph\u00e9p \u0111\u1ecdc l\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng. D\u1eef li\u1ec7u c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c \u0111\u1ecdc v\u00e0 con tr\u1ecf file c\u00f3 th\u1ec3 di chuy\u1ec3n tr\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng. K\u1ebft h\u1ee3p v\u1edbi GENERIC_WRITE \u0111\u1ec3 truy c\u1eadp d\u1ea1ng \u0111\u1ecdc/ghi.

GENERIC_WRITE Ch\u1ec9 \u0111\u1ecbnh ph\u01b0\u01a1ng th\u1ee9c cho ph\u00e9p ghi l\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng. D\u1eef li\u1ec7u c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c ghi v\u00e0 con tr\u1ecf file c\u00f3 th\u1ec3 di chuy\u1ec3n tr\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng. K\u1ebft h\u1ee3p v\u1edbi GENERIC_READ \u0111\u1ec3 truy c\u1eadp d\u1ea1ng \u0111\u1ecdc/ghi.

dwShareMode

[v\u00e0o] Ch\u1ebf \u0111\u1ed9 chia s\u1ebb cho \u0111\u1ed1i t\u01b0\u1ee3ng. N\u1ebfudwShareMode = 0, \u0111\u1ed1i t\u01b0\u1ee3ng kh\u00f4ng th\u1ec3 chia s\u1ebb. C\u00e1c thao t\u00e1c b\u00ean trong \u0111\u1ed1i t\u01b0\u1ee3ng s\u1ebb kh\u00f4ng th\u00e0nh c\u00f4ng cho \u0111\u1ebfn khi handle \u0111\u01b0\u1ee3c \u0111\u00f3ng.

Tham s\u1ed1 n\u00e0y c\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u gi\u00e1 tr\u1ecb kh\u00e1c nhau. B\u1ea3ng sau s\u1ebb cho th\u1ea5y c\u00e1c gi\u00e1
tr\u1ecb th\u00edch h\u1ee3p c\u1ee7adw Shar e Mode.
Gi\u00e1 tr\u1ecb
M\u00f4 t\u1ea3
FILE_SHARE_READ
Thao t\u00e1c con tr\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng ch\u1ec9 c\u00f3 th\u1ec3 th\u00e0nh c\u00f4ng
ch\u1ec9 khi th\u1ef1c hi\u1ec7n \u0111\u1ecdc file.
FILE_SHARE_WRITE
Thao t\u00e1c con tr\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng ch\u1ec9 c\u00f3 th\u1ec3 th\u00e0nh c\u00f4ng
ch\u1ec9 khi ghi file.
lpSecurityAttributes
[v\u00e0o] Lu\u00f4n = NULL.
dwCreationDispostion
[v\u00e0o] S\u1ef1 ki\u1ec7n x\u1ea3y ra khi file \u0111ang t\u1ed3n t\u1ea1i, v\u00e0 kh\u00f4ng t\u1ed3n t\u1ea1i. B\u1ea3ng sau m\u00f4 t\u1ea3
c\u00e1c g\u00eda tr\u1ecb kh\u1ea3 d\u1ee5ng chodwCr eationDis pos tion.
Gi\u00e1 tr\u1ecb
M\u00f4 t\u1ea3
CREATE_NEW
T\u1ea1o m\u1edbi file. H\u00e0m kh\u00f4ng th\u00e0nh c\u00f4ng n\u1ebfu file \u0111ang
t\u1ed3n t\u1ea1i.
CREATE_ALWAYS
T\u1ea1o m\u1edbi file. N\u1ebfu file \u0111\u00e3 t\u1ed3n t\u1ea1i th\u00ec s\u1ebd ghi \u0111\u00e8.
OPEN_EXISTING
M\u1edf file. H\u00e0m kh\u00f4ng th\u00e0nh c\u00f4ng n\u1ebfu file kh\u00f4ng t\u1ed3n
t\u1ea1i.
Ph\u1ea3i s\u1eed d\u1ee5ng c\u1edd n\u00e0y khi m\u1edf thi\u1ebft b\u1ecb b\u1eb1ng h\u00e0m
createfile() bao g\u1ed3m c\u1ea3 console.
OPEN_ALWAYS

M\u1edf file n\u1ebfu n\u00f3 t\u1ed3n t\u1ea1i. N\u1ebfu kh\u00f4ng, t\u1ea1o file nh\u01b0
tr\u01b0\u1eddng h\u1ee3p c\u1edddwCr e ationDis pos ition \u0111\u01b0\u1ee3c \u0111\u1eb7t l\u00e0
CREATE_NEW.

TRUNCATE_EXISTING M\u1edf file. M\u1edf m\u1ed9t l\u1ea7n, file b\u1ecb c\u1eaft b\u1edbt n\u00ean k\u00edch th\u01b0\u1edbc
c\u1ee7a n\u00f3 l\u00e0 0 bytes. Ph\u1ea3i ch\u1ec9 \u0111\u1ecbnh truy c\u1eadp
GENERIC_WRITE \u0111\u1ed1i v\u1edbi lo\u1ea1i c\u1edd n\u00e0y. H\u00e0m th\u1ea5t b\u1ea1i
n\u1ebfu file kh\u00f4ng t\u1ed3n t\u1ea1i.

dwFlagsAndAttributes
[in] Thu\u1ed9c t\u00ednh v\u00e0 c\u1edd cho file.

M\u1ecdi s\u1ef1 k\u1ebft h\u1ee3p c\u00e1c thu\u1ed9c t\u00ednh c\u00f3 th\u1ec3 c\u00f3 c\u1ee7a file \u0111\u1ec1u \u0111\u01b0\u1ee3c ch\u1ea5p nh\u1eadn \u0111\u1ed1i v\u1edbi tham s\u1ed1dwFlagsAndAttributes. T\u1ea5t c\u1ea3 c\u00e1c thu\u1ed9c t\u00ednh kh\u00e1c \u0111\u1ec1u ch\u1ee9a thu\u1ed9c t\u00ednh FILE_ATTRIBUTE_NORMAL. b\u1ea3ng sau m\u00f4 t\u1ea3 c\u00e1c thu\u1ed9c t\u00ednh c\u00f3 th\u1ec3 c\u1ee7a

dwFlagsAndAttributes.
Value
Description
FILE_ATTRIBUTE_ARCHIVE

X\u00e1c \u0111\u1ecbnh file c\u00f3 th\u1ec3 l\u01b0u tr\u1eef. \u1ee8ng d\u1ee5ng
d\u00f9ng thu\u1ed9c t\u00ednh n\u00e0y \u0111\u1ec3 \u0111\u00e1nh d\u1ea5u file trong
tr\u01b0\u1eddng h\u1ee3p sao l\u01b0u hay lo\u1ea1i b\u1ecf.

FILE_ATTRIBUTE_HIDDEN
X\u00e1c \u0111\u1ecbnh file b\u1ecb \u1ea9n. N\u00f3 kh\u00f4ng c\u00f3 trong
danh s\u00e1ch c\u1ee7a m\u1ed9t th\u01b0 m\u1ee5c th\u00f4ng th\u01b0\u1eddng.
FILE_ATTRIBUTE_NORMAL

X\u00e1c \u0111\u1ecbnh r\u1eb1ng file kh\u00f4ng c\u00f3 t\u1eadp thu\u1ed9c t\u00ednh n\u00e0o kh\u00e1c. Thu\u1ed9c t\u00ednh n\u00e0y ch\u1ec9 \u0111\u00fang n\u1ebfu s\u1eed d\u1ee5ng m\u1ed9t m\u00ecnh.

FILE_ATTRIBUTE_READONLY X\u00e1c \u0111\u1ecbnh r\u1eb1ng file l\u00e0 ch\u1ec9 \u0111\u1ecdc.
FILE_ATTRIBUTE_SYSTEM
X\u00e1c \u0111\u1ecbnh file l\u00e0 m\u1ed9t ph\u1ea7n hay \u0111\u01b0\u1ee3c d\u00e0nh
ri\u00eang cho h\u1ec7 \u0111i\u1ec1u h\u00e0nh (OS).
FILE_ATTRIBUTE_TEMPORARY Kh\u00f4ng \u0111\u01b0\u1ee3c h\u1ed7 tr\u1ee3.
M\u1ecdi s\u1ef1 k\u1ebft h\u1ee3p c\u00e1c c\u1edd cho ph\u00e9p \u0111\u1ec1u \u0111\u01b0\u1ee3c ch\u1ea5p nh\u1eadn \u0111\u1ed1i v\u1edbi tham s\u1ed1
dwFlagsAndAttributes. B\u1ea3ng sau cho th\u1ea5y c\u00e1c gi\u00e1 tr\u1ecb c\u1edd cho ph\u00e9p \u0111\u1ed1i v\u1edbi
dwFlagsAndAttributes.
Gi\u00e1 tr\u1ecb
M\u00f4 t\u1ea3

FILE_FLAG_WRITE_THROUGH Ch\u1ec9 \u0111\u1ecbnh h\u1ec7 th\u1ed1ng ngay l\u1eadp t\u1ee9c cache v\u00e0 ghi d\u1eef li\u1ec7u l\u00ean \u0111\u0129a. H\u1ec7 th\u1ed1ng v\u1eabn \u0111\u1ec7m qu\u00e1 tr\u00ecnh ghi, nh\u01b0ng kh\u00f4ng th\u1ec3 ch\u1eadm tr\u1ec5 trong vi\u1ec7c

Activity (5)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
Danh Dũng liked this
Lê Xuân Hoài liked this
haibumt liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->