Thread: Why does my prog just stop?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Why does my prog just stop?

    Why does this program just stop right after checkpoint 3 comes up? I know it has somthing to do with the InternetReadFile(), but this script has worked before.

    MY_PASSWORD is just that. But my real one goes there in my program. And IE executes these address' just fine.

    Thanks for any help, August.

    Code:
     #include <tchar.h>
    #include <gwc.h> // Holds cp(int);
    void tGetInternetFile(char buffer[], LPCTSTR szURL, size_t cbMaxSize, size_t* lpcbActualSize)
    {
    HINTERNET hNet		 = NULL;
    HINTERNET hUrlFile	 = NULL;
    DWORD	 cbBytesRead = 0;
    SIZE_T	cbBytesTotal = 0;
    BOOL	 bResult	 = FALSE;
    const DWORD cbReadSize = 0x4000;
     
    cp(0);
     
    	if (!(hNet = InternetOpen(TEXT("Downloader"), PRE_CONFIG_INTERNET_ACCESS, NULL, NULL, 0)))
    	{
    		cp(-1);
    goto cleanup;
    	}
    	else
    		cp(1);
     
    if (!(hUrlFile = InternetOpenUrl(hNet, szURL, NULL, 0, INTERNET_FLAG_RESYNCHRONIZE, 0)))
    	{
    		cp(-2);
    goto cleanup;
    	}
    	else
    		cp(2);
     
    do
    {
    if (!(buffer = (char*) ReallocOrFree(buffer, cbBytesTotal + cbReadSize)))
    		{
    			cp(-3);
    goto cleanup;
    		}
    		else
    			cp(3);
     
    if (!InternetReadFile(hUrlFile, buffer + cbBytesTotal, cbReadSize, &cbBytesRead))
    		{
    			cp(-4);
    goto cleanup;
    		}
    		else
    			cp(4);
     
    cbBytesTotal += cbBytesRead;
     
    /* Max size check and size_t overflow check */
    if (cbBytesTotal > cbMaxSize || ((((size_t) -1) - cbReadSize) - 1) < cbBytesTotal)
    		{
    			cp(-5);
    goto cleanup;
    		}
    		else
    			cp(5);
     
    } while (cbBytesRead > 0);
     
    if (!(buffer = (char*) ReallocOrFree(buffer, cbBytesTotal + 1)))
    	{
    		cp(-6);
    goto cleanup;
    	}
    	else
    		cp(6);
     
    buffer[cbBytesTotal] = '\0';
    bResult = TRUE;
     
    cleanup:
    if (hUrlFile) InternetCloseHandle(hUrlFile);
    if (hNet)	 InternetCloseHandle(hNet);
    if (!bResult) free(buffer);
    if (lpcbActualSize) *lpcbActualSize = (bResult ? cbBytesTotal : 0);
     
    return;
    }
     
    void DoIt()
    {
    size_t sz;
    char my_temp_buff[10];
    char my_buffer[200];
     
      tGetInternetFile(my_temp_buff,"http://cboard.cprogramming.com/login.php?vb_login_username=Cool-August&cookieuser=1&vb_login_password=sulten&do=login",10,&sz);
      tGetInternetFile(my_buffer,"http://cboard.cprogramming.com/usercp.php?",sizeof(my_buffer),&sz);
      tGetInternetFile(my_temp_buff,"http://cboard.cprogramming.com/login.php?do=logout&u=14571",10,&sz);
     
     
    QuickWrite("my_file.txt",my_buffer);
    }
     
    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
     
    /* Make the class name into a global variable */
    char szClassName[ ] = "WindowsApp";
     
    /* Make the paint variable available globally */
    HDC hdc;
     
    int WINAPI WinMain (HINSTANCE hThisInstance,
    					HINSTANCE hPrevInstance,
    					LPSTR lpszArgument,
    					int nFunsterStil)
    {
    	HWND hwnd;			 /* This is the handle for our window */
    	MSG messages;			/* Here messages to the application are saved */
    	WNDCLASSEX wincl;		/* Data structure for the windowclass */
     
    	/* The Window structure */
    	wincl.hInstance = hThisInstance;
    	wincl.lpszClassName = szClassName;
    	wincl.lpfnWndProc = WindowProcedure;	 /* This function is called by windows */
    	wincl.style = CS_DBLCLKS;				 /* Catch double-clicks */
    	wincl.cbSize = sizeof (WNDCLASSEX);
     
    	/* Use default icon and mouse-pointer */
    	wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    	wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    	wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    	wincl.lpszMenuName = NULL;				 /* No menu */
    	wincl.cbClsExtra = 0;					 /* No extra bytes after the window class */
    	wincl.cbWndExtra = 0;					 /* structure or the window instance */
    	/* Use Windows's default color as the background of the window */
    	wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
     
    	/* Register the window class, and if it fails quit the program */
    	if (!RegisterClassEx (&wincl))
    		return 0;
     
    	int winX = 544;
    	int winY = 375;
     
    	/* The class is registered, let's create the program*/
    	hwnd = CreateWindowEx (
    		 0,				 /* Extended possibilites for variation */
    		 szClassName,		 /* Classname */
    		 "Windows Application",	 /* Title Text */
    		 WS_OVERLAPPEDWINDOW&~WS_THICKFRAME&~WS_MAXIMIZEBOX,
    		 GetSystemMetrics(SM_CXSCREEN)/2-winX/2,	 /* Windows decides the position */
    		 GetSystemMetrics(SM_CYSCREEN)/2-winY/2,	 /* where the window ends up on the screen */
    		 winX,				 /* The programs width */
    		 winY,				 /* and height in pixels */
    		 HWND_DESKTOP,		/* The window is a child-window to desktop */
    		 NULL,				/* No menu */
    		 hThisInstance,	 /* Program Instance handler */
    		 NULL				 /* No Window Creation data */
    		 );
     
    	/* Make the window visible on the screen */
    	ShowWindow (hwnd, nFunsterStil);
     
    	/* Get the window's DC */
    	hdc = GetDC(hwnd);
     
    	/* Run the message loop. It will run until GetMessage() returns 0 */
    	while (GetMessage (&messages, NULL, 0, 0))
    	{
    		/* Translate virtual-key messages into character messages */
    		TranslateMessage(&messages);
    		/* Send message to WindowProcedure */
    		DispatchMessage(&messages);
    	}
     
    	/* The program return-value is 0 - The value that PostQuitMessage() gave */
    	return messages.wParam;
    }
     
     
    /* This function is called by the Windows function DispatchMessage() */
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch (message)				 /* handle the messages */
    	{
    		case WM_CREATE:
    		{
    			DoIt(); 
    		}
    		break;
     
    		case WM_DESTROY:
    		{
    			PostQuitMessage (0);
    		}
    		break;
     
    		default:
    		return DefWindowProc (hwnd, message, wParam, lParam);
    	}
     
    	return 0;
    }
    Last edited by Queatrix; 02-27-2006 at 12:04 PM. Reason: Getting rid of the links that the richedit put in my code!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  2. Error stop Http Listener
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-04-2008, 02:14 AM
  3. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  4. How do I stop cin from crashing my prog
    By Panopticon in forum C++ Programming
    Replies: 10
    Last Post: 12-13-2004, 03:41 PM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM