Thread: Basic Window Creation, Dev C++ Linking Error

  1. #1
    Registered User
    Join Date
    Mar 2004

    Basic Window Creation, Dev C++ Linking Error

    I'm creating a basic window, with the code below. I get the error: [Linker error] undefined reference to 'GetStockObject@4'

    Can anyone help me through this? I have no idea what's up with this code..
    #include <windows.h>
    /* Message handler prototype */
    LRESULT CALLBACK WndProc(HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam);
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
        /* The Window Class */
        WNDCLASS kWndClass;
        /* 'Visual' properties */
        kWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
        kWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        kWndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
        /* System properties */
        kWndClass.hInstance = hInstance;
        kWndClass.lpfnWndProc = WndProc;
        kWndClass.lpszClassName = "01 Basic Window";
        /* Extra properties */
        kWndClass.lpszMenuName = NULL;
        //kWndClass.cbClsExtra = NULL;
        //kWndClass.cbWndExtra = NULL; = 0;
        /* Try to register class */
        if(!RegisterClass (&kWndClass))
            return -1;
            /* The Window */
            HWND hWindow;
            /* Create the window */
            hWindow = CreateWindow("01 Basic Window", "A Blank Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
            /* The Message Loop */
            MSG kMessage;
            /* Enter the message loop and deal with all the messages sent to our window */
            while(GetMessage(&kMessage, hWindow, 0, 0))
    return 0; 
    /* The Message Handler */
    LRESULT CALLBACK WndProc(HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam)
            case WM_CLOSE:
                return DefWindowProc(hWindow, iMessage, wParam, lParam);
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  2. #2
    Join Date
    Jan 2002
    You haven't linked with the gdi32 library. Try re-creating your project as a 'windows application' which should ensure the necessary libraries are properly linked. It will also provide you with the source code for a basic window.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Join Date
    Oct 2004
    250 has a good window layout better than the default one for DEV C++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM