EvilZone
Programming and Scripting => C - C++ => : SajibFinix March 04, 2013, 06:17:41 PM
-
This following program isn't compiling.......
#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;
}
Its showing following error on Code::Blocks
Build Log:
Compiling: D:\Stuff\Personal\Sajib\Programming\C Codes\Test\Untitled1.c
Linking console executable: D:\Stuff\Personal\Sajib\Programming\C Codes\Test\Untitled1.exe
D:\Stuff\Personal\Sajib\Programming\C Codes\Test\Untitled1.o:Untitled1.c:(.text+0x96): undefined reference to `GetStockObject@4' /*At line 25*/
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings[/code]
But I don't Know What wrong with this GetStockObject!! Its right i think
-
CodeBlocks Wiki (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)
Q: How do I troubleshoot a compiler problem?A: I would start by turning on full Compiler logging.This is done by selecting the "Full command line" option Under menu "Settings" -> "Compiler" -> Global compiler settings -> [the compiler you use] -> "Other Setting" tab, "Compiler logging". In 12.11 and newer this is enabled by default.This option will make Code::Blocks output the exact commands it uses to compile your code.Things to remember:You should review all the commands and their options;[/q]
[/font][/size]- If you have compiled your app before, do a re-build (or clean before build) to see all compiling / linking steps;
- If you don't know what an option or a command does please read the documentation for the compiler/linker you're using;
- Look for missing commands;
- For every source file (.cpp; .c; .d; etc) in your project, you must have at least one command in the log. This command must produce an object file (file extension .o if using gcc/g++ and .obj if using Visual Studio);
- Every object file should be linked in the final executable, if not there are undefined symbols errors;
- Remember the file extension matters: *.c is compiled as C file, *.cpp is compiled as C++ file.
- [/l]
Post an intro about your self.
-
Add -lgdi32 to your linker options.
-
Thanks.
Its working!!
But what is Linker Options? @Deque
-
Thanks.
Its working!!
But what is Linker Options? @Deque
The options of a linker. ;)
And before you ask what a linker is. This: https://en.wikipedia.org/wiki/Linker_%28computing%29
-
:D
Thanks.