Thread: Error: Implicit conversion from void*

  1. #1
    Unregistered
    Guest

    Exclamation Error: Implicit conversion from void*

    I get this error when I try to compile the follow line of code:

    ANSI C++ forbids implicit conversion from `void *' in argument passing

    referring to:

    UnregisterClass( "Window", wc.hInstance );//wc is a WNDCLASSEX

    AHH...why won't it just work! And why does it say 'void *'; I don't even see that anywhere in the source or headers for the class.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    void * = (roughtly) char * = byte *

    Unless you are using a pointer to your winclass wc , then use wc->hInstance, I get no problem with MSVC 5 / 97 but I use C no ++.
    "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

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    70
    It's because hInstance member of WNDCLASSEX is of type HANDLE which is internally defined as (void *). UnregisterClass () awaits HINSTANCE type as the second argument. This type is probably something else. ANSI C++ forces programmer to cast (void *) pointers to proper types before passing them as arguments. This line solves your problem:

    UnregisterClass ( "Window", (HINSTANCE) wc.hInstance );

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    In MSVC 5 / 97

    WNDCLASSEX hInstance is recorded as a HANDLE in the help but is declared as a HINSTANCE in its header.

    Not that this helps anyone...
    "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

  5. #5
    Unregistered
    Guest
    While it is true in VC++ 4 to 6, casting hInstance to HINSTANCE is
    unneeded. Guest didn't state what version of compiler he has. There's no problem if it is Visual 5.

  6. #6
    Unregistered
    Guest
    Thanks everybody! I got it working right now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  4. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 06:18 PM
  5. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 09:44 PM