Thread: issues

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    11

    issues

    i tried running this program and got an error. the code is copy/pasted from a cd included with the book i'm learning from so i don't understand the error. can anyone help.

    here is a screen of what i see....
    http://www.uploadfile.info/uploads/7a977368d1.jpg

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    It is better to place the code in your post.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    why are you casting to void* ?

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    oh alright then here you go, this is the function i am having issues with...

    Code:
    void DrawBitmap(HDC hdcDest, char *filename, int x, int y)
    {
         HBITMAP image;
         BITMAP bm;
         HDC hdcMem;
         
         //load the bitmap image
         image = (void*)LoadImage(0,"c.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
         
         //read the bitmap's properties
         GetObject(image, sizeof(BITMAP), &bm);
         
         //create a device context for the bitmap
         hdcMem = CreateCompatibleDC(global_hdc);
         SelectObject(hdcMem, image);
         
         //draw the bitmap to the window (bit block transfer)
         BitBlt(
                global_hdc,               //destination device context
                x, y,                     //x, y location on destination
                bm.bmWidth, bm.bmHeight,  //width, height of source bitmap
                hdcMem,                   //soource bitmap device context
                0, 0,                     //start x,y on source bitmap
                SRCCOPY);                 //blit method
                
         //delete the device context and bitmap
         DeleteDC(hdcMem);
         DeleteObject((HBITMAP)image);
    }
    i posted the screen so that you could see what error i'm getting and all that stuff.

    but for those who don't like to click the error i get is

    In function 'void DrawBitmap(HDC__*, char*, int, int)'
    invalid conversion from 'void*' to 'HBITMAP__*'
    [Build Error] [winmain.o] Error 1
    thanks for any help.

    EDIT: just saw the next post. i don't know why, i copied this code from a cd included with the book i'm learning out of. but removing the (void*) casting still produces the same error.

  5. #5
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    I doubt this person is the writer of the program. I am going to assume that you didn't write this code originally. Take the code to where you got it and ask them about the errors.

    EDIT: Ahh code from a book... check for the books site to see if there is any updated code... perhaps it is made for a older compiler.

  6. #6
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    no didn't but i can't ask a book and expect and answer when it is sure it is right.

  7. #7
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    EDIT: just saw the next post. i don't know why, i copied this code from a cd included with the book i'm learning out of. but removing the (void*) casting still produces the same error.
    this may sound a little crazy, but you could always try to edit the code.

    you know like remove the cast to void* and see what happens.

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    wow you guys don't read much....
    i said in first post i copied it from a book
    and you quoted me yourself when i said that removing the cast still produces the same error...

    anyway thanks for the responses, any other ideas?

  9. #9
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    ...why not cast it to a HBITMAP?

  10. #10
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    Quote Originally Posted by Logan1033
    wow you guys don't read much....
    i said in first post i copied it from a book
    and you quoted me yourself when i said that removing the cast still produces the same error...

    anyway thanks for the responses, any other ideas?
    hehe that is funny. i dont have much of a defense for that one..

  11. #11
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    ok i tried and it actually compiled and ran this time but it didn't produce the output desired.
    oh well, thank you for answering my question, i'll go figure out what the other problem is now.

  12. #12
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You still haven't told us what book you're using.

    > Ahh code from a book... check for the books site to see if there is any updated code... perhaps it is made for a older compiler.
    This is some good advice: most C books worth anything have an errata list on the author's website. If you don't know the url, you can google the author's name and see what you find.

  13. #13
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    i'm using Beginning Game Programming(Game Development) by Jonathan S. Harbour.
    i read a c primer before this so i wouldn't be so confused but dealing with the windows API still confuses me. the compiler is not the problem as i am using the onw provided on the cd because i was worried about just that sort of problem.

    this code is supposed to load a bitmap image to the window in random locations until i end the program, but al that comes up is a blank black window. could this be related to the problem i thought i just solved?


    EDIT: ok i could claim ignorance about the first problem but this one is just me being stupid. i forgot the show the comiler where to find the image i wanted loaded. thank you guys very much. i'm sure i will post back with other problem as i work through this book.... i just hope next time you guys read the post a little more carefully
    Last edited by Logan1033; 08-16-2006 at 01:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Better spacing issues
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2008, 04:46 PM
  2. Bitmap scroll issues
    By Gerread in forum Windows Programming
    Replies: 4
    Last Post: 05-14-2007, 05:18 AM
  3. Issues with if statement
    By tameeyore in forum C Programming
    Replies: 7
    Last Post: 09-27-2004, 09:34 PM
  4. gphoto2 issues
    By axon in forum Tech Board
    Replies: 3
    Last Post: 03-21-2004, 08:33 PM
  5. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM