News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Program Is Not Running In Code Blocks.But It Should!

Started by SajibFinix, March 04, 2013, 03:31:47 PM

Previous topic - Next topic

SajibFinix

This following program is not compiling in code::blocks

#include <windows.h>

LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);

char szWinName[] = "MyWin"; //window clss name

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInts, LPSTR lpszArgs, int nWinMode){

    HWND hwnd;
    MSG msg;
    WNDCLASSEX wcl;

    /*define window clss*/
    wcl.cbSize = sizeof(WNDCLASSEX); //size of WNDCLASSEX
    wcl.hInstance = hThisInst; //Handle to this instance
    wcl.lpszClassName = szWinName; //window class name
    wcl.lpfnWndProc = WindowFunc; //window function
    wcl.style = 0; //default style
    wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //icon style
    wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO); //small icon style
    wcl.hCursor = LoadCursor(NULL, IDC_ARROW); //Cursor style
    wcl.lpszMenuName = NULL; //as no menu
    wcl.cbClsExtra = 0; //as no extra
    wcl.cbWndExtra = 0; //information needed
    wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); //Window Background: White
    if(!RegisterClassEx(&wcl)) return 0;

    /*Now a window class has been registered, a window can be created*/
    hwnd = CreateWindow(
        szWinName, //name of window class as prmtr
        "Window Skeleton", //Title
        WS_OVERLAPPEDWINDOW, // Window Style: Normal
        CW_USEDEFAULT, // X coordinate: Let Window Choose
        CW_USEDEFAULT, // Y coordinate: Let Window Choose
        CW_USEDEFAULT, // Width: Let Window Choose
        CW_USEDEFAULT, // Height: Let Window Choose
        HWND_DESKTOP, // No parent window
        NULL, // As No Menu
        hThisInst, // Handle to this Instance of the program
        NULL // No Additional Arguments
    );

    /*Display The Window*/
    ShowWindow(hwnd, nWinMode);
    UpdateWindow(hwnd);

    /*Creat The Message Loop*/
    while(GetMessage(&msg, NULL, 0, 0)){
        TranslateMessage(&msg); // Translate Keyboard Message
        DispatchMessage(&msg); // Return Control To Window
    }
    return msg.wParam;
}

/*This Function Called By Window And Is Passed Message from queue*/
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    switch(message){
        case WM_DESTROY: // Terminate the program
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hwnd, message, wParam, lParam); //Let window process message
    }
    return 0;
}


It gives following error.
Build Log:
D:\Stuff\Personal\Sajib\Programming\C Codes\Test\Untitled1.o:Untitled1.c:(.text+0x96): undefined reference to `GetStockObject@4' //See Line 25
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings

oBFusCATed

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Jenna

Quote from: oBFusCATed on March 04, 2013, 03:35:56 PM
And please read the rules of the forum, you're violating it...

Do not only read, but also respect them.

The error is compiler/linker related but not Code::Blocks related, that 's one violation.
You also did not search the web for a solution (obviously), because the correct answer is easy to find.

Be aware, that according to the rules such posts can be deleted or locked silently.