Why does my prog just stop?

This is a discussion on Why does my prog just stop? within the Windows Programming forums, part of the Platform Specific Boards category; Why does this program just stop right after checkpoint 3 comes up? I know it has somthing to do with ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005

    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.

     #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;
    	if (!(hNet = InternetOpen(TEXT("Downloader"), PRE_CONFIG_INTERNET_ACCESS, NULL, NULL, 0)))
    goto cleanup;
    if (!(hUrlFile = InternetOpenUrl(hNet, szURL, NULL, 0, INTERNET_FLAG_RESYNCHRONIZE, 0)))
    goto cleanup;
    if (!(buffer = (char*) ReallocOrFree(buffer, cbBytesTotal + cbReadSize)))
    goto cleanup;
    if (!InternetReadFile(hUrlFile, buffer + cbBytesTotal, cbReadSize, &cbBytesRead))
    goto cleanup;
    cbBytesTotal += cbBytesRead;
    /* Max size check and size_t overflow check */
    if (cbBytesTotal > cbMaxSize || ((((size_t) -1) - cbReadSize) - 1) < cbBytesTotal)
    goto cleanup;
    } while (cbBytesRead > 0);
    if (!(buffer = (char*) ReallocOrFree(buffer, cbBytesTotal + 1)))
    goto cleanup;
    buffer[cbBytesTotal] = '\0';
    bResult = TRUE;
    if (hUrlFile) InternetCloseHandle(hUrlFile);
    if (hNet)	 InternetCloseHandle(hNet);
    if (!bResult) free(buffer);
    if (lpcbActualSize) *lpcbActualSize = (bResult ? cbBytesTotal : 0);
    void DoIt()
    size_t sz;
    char my_temp_buff[10];
    char my_buffer[200];
    /* Declare Windows procedure */
    /* 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 */
    		 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 */
    		/* Send message to WindowProcedure */
    	/* 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:
    		case WM_DESTROY:
    			PostQuitMessage (0);
    		return DefWindowProc (hwnd, message, wParam, lParam);
    	return 0;
    Last edited by Queatrix; 02-27-2006 at 11:04 AM. Reason: Getting rid of the links that the richedit put in my code!

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Well here's one problem:

    goto cleanup;
    Try finding a way around not using goto's, and see if that clears up anything.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Banks of the River Styx
    Hmm... not sure why'd it'd just stop truthfully, but here's a couple of things I notice:

    Your buffer is an array. It appears you reallocate the buffer [array]. If you're reallocating a buffer, is there a possibility that the pointer to the buffer might change? (Since you're setting it, probably.) If you set buffer to a new value, the calling function will have no knowledge of this!

    How does QuickWrite know the size of the buffer it's writing? What do cp() and ReallocOrFree() do?

    This confuses me:
    if (cbBytesTotal > cbMaxSize || ((((size_t) -1) - cbReadSize) - 1) < cbBytesTotal)
    The first time through, would the second part of that not be:
    -1 - 0x4000 - 1 < 0x4000... which is always true?

    Finally, indent. Indent, please! It makes reading easier, trust me.

    And what's wrong with using gotos? (In that sense) Yes, his code could be rewritten to not use them, but he'd have to free the resources in each error check, would he not? Terribly tedious. Adding other things such as file handles, or allocated memory, would be harder to add.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    1. The indentation sucks.

    2. If you had decent indentation, then it would be obvious that having goto's out of and if/else chain is pointless, because that is where you're going anyway, so there really is no point in banging on about it.

    3. ReallocOrFree
    What you pass to this first is NOT something you alloced, but a local array on the stack.
    Just sit back and wait for the boom.

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    This is just some example script that anyotmouse or what ever his user-name is, gave me a link to on this board.

    take a look cactus hugger:

    QuickWrite(char szTitle[], char szData[]);

    As you can see, it doesn't have to know. And I also use QuickWrite a lot, and it has never let me down.

    cp() just lets me know if it has been reached, that way I can know where my code has the problems.

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, 02: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21