Annoying SelectObject error!

This is a discussion on Annoying SelectObject error! within the Windows Programming forums, part of the Platform Specific Boards category; I am running the following function, and the bolded line is having this error: "ANSI C++ forbids implicit conversion from ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    25

    Annoying SelectObject error!

    I am running the following function, and the bolded line is having this error:
    "ANSI C++ forbids implicit conversion from `void *' in assignment"

    Here is the function:
    Code:
    void Board::RefreshBoard(Piece* currentPiece, HDC BoardHDC)
    {
       bool check;
    
       HBITMAP hbmCurrentSq,hbmOld;
       HWND hwnd;
       HINSTANCE hInst = GetModuleHandle(NULL);
       
       hbmSquare[0] = LoadBitmap(hInst, "WHITEBMP");
       hbmSquare[1] = LoadBitmap(hInst, "GREENBMP");
       hbmSquare[2] = LoadBitmap(hInst, "YELLOWBMP");
       hbmSquare[3] = LoadBitmap(hInst, "REDBMP");
       hbmSquare[4] = LoadBitmap(hInst, "PURPLEBMP");
       hbmSquare[5] = LoadBitmap(hInst, "BLUEBMP");
       hbmSquare[6] = LoadBitmap(hInst, "ORANGEBMP");
        
       if(!hbmSquare[0] || !hbmSquare[1] || !hbmSquare[2] || !hbmSquare[3] || !hbmSquare[4] || !hbmSquare[5] || !hbmSquare[6])
           MessageBox(hwnd, "You hit a c!", "C baby", MB_OK | MB_ICONEXCLAMATION);
    
        for(int y=0; y<20; y++)
        {
            for(int x=0; x<10; x++)
            {
                if(theBoard[x][y] > 0)
                {
                    HDC hdcMemory2;
                    hdcMemory2 = CreateCompatibleDC(BoardHDC);
                    hbmCurrentSq = hbmSquare[theBoard[x][y]-1];
                    hbmOld = SelectObject(hdcMemory2, hbmCurrentSq);
                    check = BitBlt(BoardHDC, x*17, y*17, 17, 17, hdcMemory2, 0, 0, SRCCOPY);
                    SelectObject(hdcMemory2, hbmOld);
                    DeleteDC(hdcMemory2);
                }
                else if(theBoard[x][y] == 0)
                   currentPiece->RemoveOneSquare(x,y);
            }
        }   
    }
    Basically I'm guessing this is returning a NULL because the SelectObject line is failing, but I don't know why it is failing. Someone tell me whats wrong! The reason I'm doing is is to try to free the default HBITMAP (from the last time it ran) that is returned everytime SelectObject runs.

    Please help!

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The error message tells you both the problem and how to fix it: The return type from SelectObject is 'void*' (actually it's HGDIOBJ but that's probably defined somewhere or other as void*)and c++ forbids an implicit conversion ie it needs a type cast (an explicit conversion) to HBITMAP.
    Code:
    HBITMAP hBmp=(HBITMAP)SelectObject(hdc,hOtherBmp);
    Or, using Fordy's inimitable style, you can just declare all your gdi objects as type 'HGDIOBJ' and never have to cast them again. Confuses the hell out of me, though.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    25
    Thanks Ken, but the funny thing is, I found that exact same answer from YOUR website, while I was looking at some code right after I posted that. Either way thank you!

    Nimit

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

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