Thread: Annoying SelectObject error!

  1. #1
    Registered User
    Join Date
    Dec 2002

    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:
    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);
                else if(theBoard[x][y] == 0)
    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
    Join Date
    Jan 2002
    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.
    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
    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!


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, 05:45 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM