User forums > General (but related to Code::Blocks)
Program Is Not Running In Code Blocks.But It Should!
(1/1)
SajibFinix:
This following program is not compiling in code::blocks
--- Code: ---#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;
}
--- End code ---
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:
Standard answer you get: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
And please read the rules of the forum, you're violating it...
Jenna:
--- Quote from: oBFusCATed on March 04, 2013, 03:35:56 pm ---And please read the rules of the forum, you're violating it...
--- End quote ---
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.
Navigation
[0] Message Index
Go to full version