您的位置:首页 > 其它

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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: