Hi all,
I am here with a problem. I am reading a file from Internet. For Example index page of "www.google.com". Once i read it I must write it into a file & I'll use this later.
The problem is that The read file is written completely into file. I didn't understood why?
Can anyone tell the reason.
I have written the code also.
// Allocate a block of memory for lpHeadersW.
lpBufferA = new CHAR [dwSize];
dwSize = MAX_PATH;
HANDLE hFile = CreateFile(_T("\\My Documents\\Config.txt"), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD dwBytesRead;
do
{
if (!InternetReadFile (hUrlRequest, (LPVOID)lpBufferA, dwSize, &dwBytesRead))
{
//Error in InternetReadFile
}
else
{
if (dwBytesRead != 0)
{
lpBufferA [dwSize] = '\0'; // Terminate headers with null.
// Get the required size of the buffer which receives the Unicode String
dwSize = MultiByteToWideChar (CP_ACP, 0, lpBufferA, -1, NULL, 0);
lpBufferW = new TCHAR [dwSize];// Allocate a block of memory for lpBufferW.
MultiByteToWideChar (CP_ACP, 0, lpBufferA, -1, lpBufferW, dwSize); WriteFile(hFile, lpBufferW,dwSize, &dwBytesRead, NULL);
delete[] lpBufferW;// Free the block of memory.
}
}
} while (dwBytesRead);
CloseHandle(hFile);
//Close all Internet Handle