Thread: Please help! What's wrong ?

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    85

    Please help! What's wrong ?

    I compiled main2.cpp with BC++ FreeCommandLine tool,
    I got this error message :

    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    main2.cpp:
    Error E2034 main2.cpp 22: Cannot convert 'void *' to 'HFONT__ *' in function __s
    tdcall WndProc(HWND__ *,unsigned int,unsigned int,long)
    Warning W8057 main2.cpp 100: Parameter 'hPrevInstance' is never used in function
    __stdcall WinMain(HINSTANCE__ *,HINSTANCE__ *,char *,int)
    Warning W8057 main2.cpp 100: Parameter 'lpCmdLine' is never used in function __s
    tdcall WinMain(HINSTANCE__ *,HINSTANCE__ *,char *,int)
    *** 1 errors in Compile ***


    Here is the WndProc function in main2.cpp:

    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    switch(msg)
    {
    case WM_CREATE:
    {
    HFONT hfDefault;
    HWND hEdit;

    hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
    WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
    0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
    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;
    case WM_SIZE:
    {
    HWND hEdit;
    RECT rcClient;

    GetClientRect(hwnd, &rcClient);

    hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
    SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
    }
    break;
    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
    }


    I really don't how to solve that error...
    Please help~

  2. #2
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Nice of you to point out which of the lines was number 22.

    > hfDefault = GetStockObject(DEFAULT_GUI_FONT);

    GetStockObject returns a HGDIOBJ, which is typedef'd to a void *. A HFONT is not a void *, so you must cast the return value:
    PHP Code:
    hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT); 
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You seem to be using just C with the win32 api, not C++ (or MFC) so why are you using .cpp files?

    You would not have the casting problem if you used .c source files instead.
    "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

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    Originally posted by Esss
    Nice of you to point out which of the lines was number 22.

    > hfDefault = GetStockObject(DEFAULT_GUI_FONT);

    GetStockObject returns a HGDIOBJ, which is typedef'd to a void *. A HFONT is not a void *, so you must cast the return value:
    PHP Code:
    hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT); 
    Thanks!
    It works !
    Thanks your help

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    Originally posted by novacain
    You seem to be using just C with the win32 api, not C++ (or MFC) so why are you using .cpp files?

    You would not have the casting problem if you used .c source files instead.
    I haven't got a tutorial about using C++ with win32 api.
    I am learning in http://www.winprog.org/ <---using C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM