Need some help at Windows Window

Hey, I'm new and dont no where is the correct place for this.
So im a beginner so post it here.

So my probelm: I try too create a window with WinApi,
I folow a toutorial but i compile came
Undifine reference to`GetStockObject`
error :ld returned 1 exit status.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #define STRICT
#include<windows.h>
HGDIOBJ GetStockObject(int iObject);
const char szAppName[] = "Ein eigenes Fenster";
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,PSTR szCmdLine,int iCmdShow)
{
    HWND       hWnd;
   MSG        msg;
   WNDCLASS   wc;

   wc.style = CS_HREDRAW|CS_VREDRAW;
   wc.lpfnWndProc=WndProc;

   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;

   wc.hInstance = hInstance;
   wc.hCursor = LoadCursor(NULL,IDC_ARROW);
   wc.hIcon  = LoadIcon(NULL,IDI_APPLICATION);
   wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

   wc.lpszClassName = szAppName;
   wc.lpszMenuName = NULL;
   RegisterClass (&wc);

   hWnd = CreateWindow(szAppName,
                       "Titteleiser",
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,   // x Pos
                       CW_USEDEFAULT,    // y pos.
                       CW_USEDEFAULT,    // Breite
                       CW_USEDEFAULT,
                       NULL,
                       NULL,
                       hInstance,
                       NULL);
    ShowWindow(hWnd,iCmdShow);
    UpdateWindow(hWnd);

    while(GetMessage(&msg,0,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);

    }
    return msg.wParam;


}LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
   {case WM_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }   return DefWindowProc(hWnd, message, wParam, lParam);
}


thanks for help!
and sry for my bad english :D
Last edited on
Remove line 3. You shouldn't declare a function from a system library.

See this:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd144925(v=vs.85).aspx

for what header/libraries are required. So you may add Gdi32.lib to your linker settings if it isn't already.
Thanks for help!
Topic archived. No new replies allowed.