VC++如何以二进制模式打开一个文件程序?

如题C可以C++也可以... 如题 C可以 C++也可以 展开
 我来答
li32568664
推荐于2016-11-26
知道答主
回答量:29
采纳率:50%
帮助的人:12.7万
展开全部
可以用 windows API, OpenFile,所有支持windowsAPI的程序都可以用。
OpenFile Function

Creates, opens, reopens, or deletes a file.

Note Only use this function with 16-bit versions of Windows. For newer applications, use the CreateFile function.

Syntax
HFILE WINAPI OpenFile(
__in LPCSTR lpFileName,
__out LPOFSTRUCT lpReOpenBuff,
__in UINT uStyle
);

Parameters
lpFileName
The name of the file.

The string must consist of characters from the Windows character set. The OpenFile function does not support Unicode file names or opening named pipes.

lpReOpenBuff
A pointer to the OFSTRUCT structure that receives information about a file when it is first opened.

The structure can be used in subsequent calls to the OpenFile function to see an open file.

The OFSTRUCT structure contains a path string member with a length that is limited to OFS_MAXPATHNAME characters, which is 128 characters. Because of this, you cannot use the OpenFile function to open a file with a path length that exceeds 128 characters. The CreateFile function does not have this path length limitation.

uStyle
The action to be taken.

This parameter can be one or more of the following values.

Value Meaning
OF_CANCEL
0x00000800
Ignored.

To produce a dialog box containing a Cancel button, use OF_PROMPT.

OF_CREATE
0x00001000
Creates a new file.

If the file exists, it is truncated to zero (0) length.

OF_DELETE
0x00000200
Deletes a file.

OF_EXIST
0x00004000
Opens a file and then closes it.

Use this to test for the existence of a file.

OF_PARSE
0x00000100
Fills the OFSTRUCT structure, but does not do anything else.

OF_PROMPT
0x00002000
Displays a dialog box if a requested file does not exist.

A dialog box informs a user that the system cannot find a file, and it contains Retry and Cancel buttons. The Cancel button directs OpenFile to return a file-not-found error message.

OF_READ
0x00000000
Opens a file for reading only.

OF_READWRITE
0x00000002
Opens a file with read/write permissions.

OF_REOPEN
0x00008000
Opens a file by using information in the reopen buffer.

OF_SHARE_COMPAT
0x00000000
For MS-DOS–based file systems, opens a file with compatibility mode, allows any process on a specified computer to open the file any number of times.

Other efforts to open a file with other sharing modes fail. This flag is mapped to the FILE_SHARE_READ|FILE_SHARE_WRITE flags of the CreateFile function.

OF_SHARE_DENY_NONE
0x00000040
Opens a file without denying read or write access to other processes.

On MS-DOS-based file systems, if the file has been opened in compatibility mode by any other process, the function fails.

This flag is mapped to the FILE_SHARE_READ|FILE_SHARE_WRITE flags of the CreateFile function.

OF_SHARE_DENY_READ
0x00000030
Opens a file and denies read access to other processes.

On MS-DOS-based file systems, if the file has been opened in compatibility mode, or for read access by any other process, the function fails.

This flag is mapped to the FILE_SHARE_WRITE flag of the CreateFile function.

OF_SHARE_DENY_WRITE
0x00000020
Opens a file and denies write access to other processes.

On MS-DOS-based file systems, if a file has been opened in compatibility mode, or for write access by any other process, the function fails.

This flag is mapped to the FILE_SHARE_READ flag of the CreateFile function.

OF_SHARE_EXCLUSIVE
0x00000010
Opens a file with exclusive mode, and denies both read/write access to other processes. If a file has been opened in any other mode for read/write access, even by the current process, the function fails.

OF_VERIFY
Verifies that the date and time of a file are the same as when it was opened previously.

This is useful as an extra check for read-only files.

OF_WRITE
0x00000001
Opens a file for write access only.

Return Value
If the function succeeds, the return value specifies a file handle.

If the function fails, the return value is HFILE_ERROR. To get extended error information, call GetLastError.
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式