conversion from 'WPARAM' to 'int' ???

This is a discussion on conversion from 'WPARAM' to 'int' ??? within the Windows Programming forums, part of the Platform Specific Boards category; I thought wparam was an int? I get the following warning from MSVC.net: ...cpp(127): warning C4244: 'return' : conversion from ...

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    conversion from 'WPARAM' to 'int' ???

    I thought wparam was an int? I get the following warning from MSVC.net:

    ...cpp(127): warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data

    Here is a snippet of my code. What am I doing wrong?
    Code:
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR lpszCmdLine, int iCmdShow)
    {
        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_CROSS);
        wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
        wndclass.lpszMenuName  = szAppName ;
        wndclass.lpszClassName = szAppName ;
        RegisterClass (&wndclass);
        hMenu = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_MENU1));
        
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        //    Allow only one instance of program!                        
        void*    hMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,PAGE_READONLY, 0, 32, szAppName);
        if (hMapping)// Check to see if app is already running                                             
        {                                                                                                 
            if (GetLastError() == ERROR_ALREADY_EXISTS)                                                     
            {                                                                                             
            SetForegroundWindow(FindWindow(szAppName, NULL));                                             
               {                                                                                         
                   CloseHandle(hMapping);                                                                 
                   ExitProcess(1);                                                                         
               }                                                                                         
            }                                                                                             
        }                                                                                                 
        else                                                                                             
        {                                                                                                 
            MessageBox(NULL, "Error creating file mapping.", "Error",MB_ICONERROR| MB_OK);            
            ExitProcess(1);                                                                                
        }                                                                                                
        // End allow only one instance of program.                                                        
        ///////////////////////////////////////////////////////////////////////////////////////////////////
    
        hwnd = CreateWindow (szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT
            , CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenu, hInstance, NULL);
        if (!hwnd) 
        {
            MessageBox(NULL, "failed window creation", "error", NULL);
            return 0;
        }
    
        ShowWindow (hwnd, iCmdShow);
        UpdateWindow (hwnd);
    
        while (GetMessage (&msg, NULL, 0, 0))
        {
             TranslateMessage (&msg);
             DispatchMessage (&msg);
        }
        return msg.wParam ;
    }
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    On Win64 a WPARAM will be 64 bits while an int will remain at 32 bits. MSVC gives this warning to forewarn you of possible problems when you try to compile your code for Win64. In this case you can use a cast and ignore the warning. More information.

    On another note, unless you need a file mapping, the preferred function to make sure your application is single-instance is CreateMutex. Also, you appear to be leaking the hMapping handle.
    Last edited by anonytmouse; 02-10-2005 at 09:59 PM.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    You can think of WPARAM as an integral type, but you still have to cast it to get rid of the warning.

    gg

  4. #4
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    I will look into CreateMutex. I just remember seeing the file mapping example here on cprogramming.com. Thank you for pointing out my hMapping leak also.
    I thought of casting to avoid the warning but I wanted to be sure I wasn't doing something stupid.

    Thanks for the quick replies!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    >>I just remember seeing the file mapping example here on cprogramming.com.

    Might be mine. Looked at other options and found that file mapping worked well enough. Never managed to make it fail so kept it.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    I wanted to say that it came from you novacain but I couldn't remember for sure!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why doesn't this example work for me?
    By xixpsychoxix in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2009, 08:25 PM
  2. Replies: 26
    Last Post: 11-30-2007, 02:51 AM
  3. Replies: 2
    Last Post: 03-24-2006, 07:36 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-01-2003, 11:26 PM

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