Invalid Conversion

This is a discussion on Invalid Conversion within the Windows Programming forums, part of the Platform Specific Boards category; Code: case WM_CREATE: { HFONT hfDefault; HWND hEdit; // Took our horizontal viewing hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | ...

  1. #1
    Amateur Programmer
    Join Date
    Nov 2003
    Posts
    11

    Question Invalid Conversion

    Code:
    	 case WM_CREATE:
    		{
    			HFONT hfDefault;
    			HWND hEdit;
       
       // Took our horizontal viewing
    			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
    				       WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 
    				       0, 0, 100, 100, hWnd, (HMENU)IDC_PRIME_EDIT, GetModuleHandle(NULL),
               NULL);
       
       // Just in case...                
    			if(hEdit == NULL)
    			{
    				MessageBox(hWnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
    			}	
    
    			hfDefault = GetStockObject(DEFAULT_GUI_FONT);
    			SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    		}
    		break;
    The error it gave me was: 42 C:\Documents and Settings\Chris\My Documents\Programming\Dingua\main.cpp invalid conversion from `void*' to `HFONT__*'

    Why?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You need to use a cast in this case:
    Code:
    hfDefault = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
    This is because GetStockObject can return other types of objects such as HBRUSH, HPEN, etc.

  3. #3
    Amateur Programmer
    Join Date
    Nov 2003
    Posts
    11
    Thank you so much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. invalid conversion from `char*' to `char'
    By Tommy7 in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2005, 11:45 PM
  5. Invalid conversion from 'const void*' to 'void*' error
    By prawntoast in forum C Programming
    Replies: 3
    Last Post: 05-01-2005, 11:30 AM

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