void CTAPIClientServerDlg::WriteFileBinData(LPCSTR szOutput, DWORD dwSize, BOOL bZeroFile)
{TCHAR szFilePrint[MAX_PATH] = TEXT(".\\out.txt");
static HANDLE hFile = NULL;
DWORD dwNumWritten;
if (hFile == NULL)
{
// hFile = CreateFile(szFilePrint, GENERIC_WRITE, FILE_SHARE_READ, NULL,
// bZeroFile ? CREATE_ALWAYS : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
hFile = CreateFile(szFilePrint, GENERIC_WRITE,
FILE_SHARE_READ, NULL,
bZeroFile ? CREATE_ALWAYS : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox("CreateFile output log file %s failed with %s\r\n");
else
SetFilePointer(hFile, 0, NULL, FILE_END);
}
if (hFile != INVALID_HANDLE_VALUE)
{
// OVERLAPPED ol = {0};
// LockFileEx(hFile, 0, 0, 1, 0, &ol);
WriteFile(hFile, szOutput, dwSize, &dwNumWritten, NULL);
// UnlockFileEx(hFile, 0, 1, 0, &ol);
}
}
#define MAX_BUFFER 256
void CTAPIClientServerDlg::ReadFileBinData(LPCSTR szOutput)
{bool bResult;
char* chRead;
DWORD dwNumByteRead=0;
HANDLE hFile = NULL;
hFile = CreateFile(szOutput, GENERIC_READ,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE
| FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY ,NULL);
if (hFile == INVALID_HANDLE_VALUE)
return;
chRead = new char[MAX_BUFFER];
for(;
{
bResult = ReadFile(hFile, chRead, MAX_BUFFER, &dwNumByteRead, NULL );
if(bResult && dwNumByteRead == 0)
{
break;
}
WriteFileBinData(chRead, dwNumByteRead);
}
delete [] chRead;
}