How DO I Get Rid Of Warnings?

This is a discussion on How DO I Get Rid Of Warnings? within the Windows Programming forums, part of the Platform Specific Boards category; Code: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // declare variables MSG msg; // register the ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    545

    How DO I Get Rid Of Warnings?

    Code:
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR     lpCmdLine,
                       int       nCmdShow)
    {
        // declare variables
    	MSG msg;
    
    	// register the class
    	MyRegisterClass(hInstance);
    
        // initialize application 
        //note--got rid of initinstance
        HWND hWnd;
    
        //create a new window
        hWnd = CreateWindow(
           APPTITLE,              //window class
           APPTITLE,              //title bar
           WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP,   //window style
           CW_USEDEFAULT,         //x position of window
           CW_USEDEFAULT,         //y position of window
           SCREEN_WIDTH,                   //width of the window
           SCREEN_HEIGHT,                   //height of the window
           NULL,                  //parent window
           NULL,                  //menu
           hInstance,             //application instance
           NULL);                 //window parameters
    
        //was there an error creating the window?
        if (!hWnd)
          return FALSE;
    
        //display the window
        ShowWindow(hWnd, nCmdShow);
        UpdateWindow(hWnd);
    	
    	//initialize the game
        if (!Game_Init(hWnd))
            return 0;
    
    
        // main message loop
        int done = 0;
    	while (!done)
        {
            if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
    	    {
                //look for quit message
                if (msg.message == WM_QUIT)
                {
                    MessageBox(hWnd, "Received WM_QUIT message", "WinMain", MB_OK);
                    done = 1;
                }
    
                //decode and pass messages on to WndProc
    		    TranslateMessage(&msg);
    		    DispatchMessage(&msg);
    	    }
            else
                //process game loop (else prevents running after window is closed)
                Game_Run(hWnd);
        }
    
    	return msg.wParam;
    }
    With the line in bold I get a warning conversion of wparam to int possible loss of data, and with the random number seed: srand(time(NULL)); I get the warning time_t to unsigned int possible loss of Data. This is code from my book on Direct_X and I would like to know why I get these errors so I can start making the full program.

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266
    Sounds like you're compiling this using a C++ compiler (i.e. your source file ends in .cpp), given that I otherwise can't see use of any specific C++ features. In C++, type checking is set to anal, so you would need to explicitly cast to remove the warnings.
    Code:
    //end of WinMain
        return (int)message.wParam;
    
    }
    and
    Code:
    srand((unsigned long)time(NULL));

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    WOW, it worked. Cheers. Yeah, the book was in C b ut I only know C++ but a lot of the code looked very familiar so I bought it.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Casting message.wParam is an unfortunate necessity, but casting the standard srand(time()) idiom might not be a good idea. Search this board for the two functions, especially for posts by Prelude.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to solve warnings that appear when building my DLL...
    By starcatcher in forum Windows Programming
    Replies: 6
    Last Post: 12-14-2008, 11:47 AM
  2. Warnings when using vector of vector
    By Boksha in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2008, 02:54 PM
  3. Replies: 9
    Last Post: 03-14-2008, 10:55 AM
  4. GCC Warnings
    By 00Sven in forum C Programming
    Replies: 12
    Last Post: 05-03-2006, 05:40 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

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