64,676
社区成员
发帖
与我相关
我的任务
分享
#include <Windows.h>
#include <tchar.h>
void foo(LPCTSTR szFileName, BYTE byFind, BYTE byReplaceWith)
{
HANDLE hFile = CreateFile(szFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return;
}
DWORD dwLength = GetFileSize(hFile, NULL);
DWORD dwBytes;
BYTE byBuffer;
for (DWORD i = 0; i < dwLength; ++i)
{
ReadFile(hFile, &byBuffer, 1, &dwBytes, NULL);
if (byBuffer == byFind)
{
SetFilePointer(hFile, -1, NULL, FILE_CURRENT);
WriteFile(hFile, &byReplaceWith, 1, &dwBytes, NULL);
}
}
CloseHandle(hFile);
}