Click here to Skip to main content
15,900,724 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Hide Command Prompt in Console Application Pin
Rolf Kristensen2-Mar-10 12:22
Rolf Kristensen2-Mar-10 12:22 
QuestionByte Ordering MFC Serialization [Solved] Pin
Garth Watkins1-Mar-10 23:05
Garth Watkins1-Mar-10 23:05 
AnswerRe: Byte Ordering MFC Serialization Pin
CPallini1-Mar-10 23:12
mveCPallini1-Mar-10 23:12 
GeneralRe: Byte Ordering MFC Serialization Pin
Garth Watkins1-Mar-10 23:17
Garth Watkins1-Mar-10 23:17 
GeneralRe: Byte Ordering MFC Serialization Pin
CPallini1-Mar-10 23:31
mveCPallini1-Mar-10 23:31 
GeneralRe: Byte Ordering MFC Serialization Pin
Garth Watkins1-Mar-10 23:44
Garth Watkins1-Mar-10 23:44 
GeneralRe: Byte Ordering MFC Serialization Pin
CPallini1-Mar-10 23:51
mveCPallini1-Mar-10 23:51 
QuestionDownload file from the url. Pin
avika1-Mar-10 22:30
avika1-Mar-10 22:30 
We want to download a file from the url.

If we are download a text file then this code will download the file successfully, but if we are trying to download a exe or even a jpg file then this code does not work fine.

We are using following code -

DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;

hSession = WinHttpOpen( L"WinHTTP Example/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);

if (hSession)
hConnect = WinHttpConnect(hSession, L"localhost.com", INTERNET_DEFAULT_HTTP_PORT, 0);
if (hConnect)
hRequest = WinHttpOpenRequest( hConnect, L"GET",
L"/CMS/upload/1.txt",
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_REFRESH);

if (hRequest)
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
WINHTTP_NO_REQUEST_DATA, 0, 0, 0);

if (bResults)
bResults = WinHttpReceiveResponse( hRequest, NULL);

if (bResults)
{
dwSize = 0;
if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
printf("Error %u in WinHttpQueryDataAvailable.\n", GetLastError());

if (dwSize > 0)
{
pszOutBuffer = new char[dwSize+1];
}

if (!pszOutBuffer)
{
printf("Out of memory\n");
dwSize=0;
}
else
{
if (dwSize>0)
{
ZeroMemory(pszOutBuffer, dwSize+1);
if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded))
printf("Error %u in WinHttpReadData.\n", GetLastError());
}
}

HANDLE hFile;
DWORD dwNumWritten;
BOOL bTest;

ofstream outfile ("D:\\1.txt",ofstream::binary);
outfile.write(pszOutBuffer,sizeof(dwSize) * 50);


Please help me what I am doing wrong.
AnswerRe: Download file from the url. Pin
«_Superman_»1-Mar-10 22:35
professional«_Superman_»1-Mar-10 22:35 
GeneralRe: Download file from the url. Pin
avika1-Mar-10 23:09
avika1-Mar-10 23:09 
GeneralRe: Download file from the url. Pin
«_Superman_»1-Mar-10 23:16
professional«_Superman_»1-Mar-10 23:16 
GeneralRe: Download file from the url. Pin
avika1-Mar-10 23:25
avika1-Mar-10 23:25 
AnswerRe: Download file from the url. Pin
CPallini1-Mar-10 22:52
mveCPallini1-Mar-10 22:52 
GeneralRe: Download file from the url. Pin
avika1-Mar-10 23:05
avika1-Mar-10 23:05 
GeneralRe: Download file from the url. Pin
CPallini1-Mar-10 23:11
mveCPallini1-Mar-10 23:11 
AnswerRe: Download file from the url. Pin
Whuili_200419-May-11 8:30
Whuili_200419-May-11 8:30 
Questionhlp its urgent Pin
DX Roster1-Mar-10 20:36
DX Roster1-Mar-10 20:36 
AnswerRe: hlp its urgent PinPopular
Cedric Moonen1-Mar-10 20:42
Cedric Moonen1-Mar-10 20:42 
AnswerRe: hlp its urgent Pin
CPallini1-Mar-10 20:44
mveCPallini1-Mar-10 20:44 
AnswerRe: hlp its urgent Pin
Paresh Chitte2-Mar-10 22:29
Paresh Chitte2-Mar-10 22:29 
GeneralRe: hlp its urgent Pin
CPallini2-Mar-10 22:45
mveCPallini2-Mar-10 22:45 
AnswerRe: hlp its urgent Pin
«_Superman_»1-Mar-10 21:10
professional«_Superman_»1-Mar-10 21:10 
GeneralRe: hlp its urgent Pin
Cedric Moonen1-Mar-10 21:13
Cedric Moonen1-Mar-10 21:13 
GeneralRe: hlp its urgent Pin
Rajesh R Subramanian1-Mar-10 21:19
professionalRajesh R Subramanian1-Mar-10 21:19 
JokeRe: hlp its urgent Pin
«_Superman_»1-Mar-10 21:23
professional«_Superman_»1-Mar-10 21:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.