Windows Dev Intro - CreateFile Relevants
2016-03-31 13:39
363 查看
hFile = CreateFile(L"D:\\Media\\SampleDocument.rtf", GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
lastErr = GetLastError();
}
nlen = GetFileSize(hFile, NULL);
if (nlen > 0) {
tt = new BYTE[nlen];
bl = ReadFile(hFile, tt, nlen, &nlen, NULL);
}
CloseHandle(hFile);
{
int i = 0;
DWORD len;
HANDLE hFile;
WCHAR txt[1024];
char ans[1024];
hFile = CreateFileW(L"test.txt", // name of the write
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
CREATE_NEW, // create new file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
for (int i = 0; i < index; i++) {
DWORD nl;
ans[0] = 0x00;
len = _swprintf(txt, L"%s %s %s %dx%d %5d %5d %5d\r\n", devcaps[i].mname, devcaps[i].name, devcaps[i].desc, devcaps[i].w, devcaps[i].h, devcaps[i].fps, devcaps[i].minfps, devcaps[i].maxfps);
nl = WideCharToMultiByte(CP_UTF8, 0, txt, -1, 0, 0, 0, FALSE);
WideCharToMultiByte(CP_UTF8, 0, txt, -1, ans, nl, 0, FALSE);
WriteFile(
hFile, // open file handle
ans, // start of data to write
nl - 1, // number of bytes to write
&nl, // number of bytes that were written
NULL); // no overlapped structure
}
CloseHandle(hFile);
}
if (hFile == INVALID_HANDLE_VALUE) {
lastErr = GetLastError();
}
nlen = GetFileSize(hFile, NULL);
if (nlen > 0) {
tt = new BYTE[nlen];
bl = ReadFile(hFile, tt, nlen, &nlen, NULL);
}
CloseHandle(hFile);
{
int i = 0;
DWORD len;
HANDLE hFile;
WCHAR txt[1024];
char ans[1024];
hFile = CreateFileW(L"test.txt", // name of the write
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
CREATE_NEW, // create new file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
for (int i = 0; i < index; i++) {
DWORD nl;
ans[0] = 0x00;
len = _swprintf(txt, L"%s %s %s %dx%d %5d %5d %5d\r\n", devcaps[i].mname, devcaps[i].name, devcaps[i].desc, devcaps[i].w, devcaps[i].h, devcaps[i].fps, devcaps[i].minfps, devcaps[i].maxfps);
nl = WideCharToMultiByte(CP_UTF8, 0, txt, -1, 0, 0, 0, FALSE);
WideCharToMultiByte(CP_UTF8, 0, txt, -1, ans, nl, 0, FALSE);
WriteFile(
hFile, // open file handle
ans, // start of data to write
nl - 1, // number of bytes to write
&nl, // number of bytes that were written
NULL); // no overlapped structure
}
CloseHandle(hFile);
}
相关文章推荐
- 代码块与函数的同步
- Log4net自定义实现httpAppender
- 常用的时间同步服务器地址
- H5移动前端开发常用高能css3汇总
- 游戏中角色类
- [查异常网]-20160331-谈谈J2EE项目中的异常处理
- Java并发编程:synchronized
- iOS 多线程自己的理解
- 用迭代实现无限级分类
- 使用nodejs抓取博客园内容---Promise模块探索
- android dialog 去标题,圆角矩形,去背景
- how-to-stop-non-jailbroken-pirates-theory
- 代码重构(二):类重构规则
- lintcode-medium-Minimum Adjustment Cost
- 一行命令搞定node.js 版本升级
- .gitignore规则不生效的解决办法
- iOS MMDrawerController侧滑菜单与中心视图手势冲突问题的解决方案
- CUDA编程(三)评估CUDA程序的表现
- .gitignore规则不生效的解决办法
- orcale _分页查询存储过程