I am working on a program that downloads a web page source, I want to put all the source in one long string. unfortunatly it seems I have to call internetreadfile several times to get a whole web page, so I was trying to figure out how to get this to work and ended up finding strcat in the microsoft VC++ docs and thought I'd found the answer to my problems.
I tried puting strcat into my program and compiled it and ran it. and nothing. the mouse changes to indicate that the program is starting up and then nothing, the program is not in memory (ctrl + alt + del, under task manager, no trace in either the applications or processes tabs)
remarking out strcat fixes the problem.
I've got a sneaking hunch that this is a stupid problem that I should know the answer to, but I did try a few things to fix it, substituting strcat for strncat, looking in the string.h file for the strcat function (couldn't find it) searching google for the same problem (found the problem but no solution)
heres a code snippet
CHAR szBuffer[1024];
CHAR szWebPage[4000];
int iTest;
while ( iTest = InternetReadFile( hFile, szBuffer, 1000, &dwRead ) )
{
if ( dwRead == 0 )
break;
szBuffer[dwRead] = 0;
strcat ( szWebPage, szBuffer}
}
heres the whole thing
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <wchar.h>
#include <string.h>
#include "stdafx.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("TestProgram") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Test Program"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
700,
150,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxChar, cxCaps, cyChar ;
static int cxClient, cyClient ;
HDC hdc ;
PAINTSTRUCT ps ;
TEXTMETRIC tm ;
// these are for placment calculations
static unsigned short int WSymbol, WShares, WWorth, WChange, WTotal;
switch (message)
{
case WM_CREATE:
hdc = GetDC (hwnd) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
cyChar = tm.tmHeight + tm.tmExternalLeading ;
WSymbol = 3 * cxCaps;
WShares = 11 * cxCaps;
WWorth = 19 * cxCaps;
WChange = 29 * cxCaps;
WTotal = 45 * cxCaps;
HINTERNET hINet, hFile;
hINet = InternetOpen("testap", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
CHAR szBuffer[1024];
CHAR szWebPage[4000];
DWORD dwRead;
CHAR szTemp[64];
int iTest;
if ( !hINet )
{
MessageBox ( hwnd, "InternetOpen Failed", "Failure", 0);
return 0;
}
hFile = InternetOpenUrl( hINet, "http://www.google.com", NULL, 0, 0, 0 ) ;
if ( hFile )
{
while ( iTest = InternetReadFile( hFile, szBuffer, 1000, &dwRead ) )
{
if ( dwRead == 0 )
break;
szBuffer[dwRead] = 0;
strcat ( szWebPage, szBuffer);
}
InternetCloseHandle( hFile );
}
InternetCloseHandle( hINet );
ReleaseDC (hwnd, hdc) ;
wsprintf ( szTemp, " %i characters where read", dwRead);
MessageBox ( hwnd, szTemp, "char's read", 0);
if (iTest)
MessageBox ( hwnd, "success!", "hurra", 0);
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Bloodshed Dev-C++ 4.9.8.0 Mingw DX 9.0a DX SDK 6.1win2k#define WIN32_LEAN_AND_MEANthe Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path.mechwarrior 2 mercenaries, 4 particle projection cannons, thug chassis