Basic Window Creation, Dev C++ 4.9.9.0 Linking Error

This is a discussion on Basic Window Creation, Dev C++ 4.9.9.0 Linking Error within the Windows Programming forums, part of the Platform Specific Boards category; I'm creating a basic window, with the code below. I get the error: [Linker error] undefined reference to 'GetStockObject@4' Can ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    220

    Basic Window Creation, Dev C++ 4.9.9.0 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..
    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;
        kWndClass.style = 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))
            {
                TranslateMessage(&kMessage);
                DispatchMessage(&kMessage);
            }
            
    return 0; 
    }
    
    /* The Message Handler */
    LRESULT CALLBACK WndProc(HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam)
    {
        switch(iMessage)
        {
            case WM_CLOSE:
            {
                PostQuitMessage(0);
                break;
            }    
            default:
                return DefWindowProc(hWindow, iMessage, wParam, lParam);
        }
    }
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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
    Banned
    Join Date
    Oct 2004
    Posts
    250
    http://winprog.org/tutorial/simple_window.html 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, 11: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-30-2005, 12:21 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM

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