Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Błąd: undefined reference to `GetStockObject@4'

Ostatnio zmodyfikowano 2015-05-23 11:06
Autor Wiadomość
sppmacd
Temat założony przez niniejszego użytkownika
Błąd: undefined reference to `GetStockObject@4'
» 2015-03-28 11:06:35
Kolejny błąd to, gdy próbuję wczytać normalną czcionkę w WinAPI:

...

D:\...\Kalkulator1\KALKULATOR.o:KALKULATOR.CPP:(.text+0xa1d): undefined reference to `GetStockObject@4'
collect2.exe: error: ld returned 1 exit status

Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 1 warning(s) (0 minute(s), 0 second(s))
 
Piszę taki program:
C/C++
#include <windows.h>
#include <string>
#include <iostream>
#define ID_PRZYCISK1 501
#define ID_PRZYCISK2 502
#define ID_PRZYCISK3 503
#define ID_PRZYCISK4 504
#define ID_PRZYCISK5 505
#define ID_PRZYCISK6 506
#define ID_PRZYCISK7 507
#define ID_PRZYCISK8 508
#define ID_PRZYCISK9 509
#define ID_FRAME 512
#define ID_FRAME1 513
#define ID_FRAME2 514



HFONT hNormalFont =( HFONT ) GetStockObject( DEFAULT_GUI_FONT );
LPSTR NazwaKlasy = "Klasa Okienka";
MSG Komunikat;

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
   
    // WYPE£NIANIE STRUKTURY
    WNDCLASSEX wc;
   
    wc.cbSize = sizeof( WNDCLASSEX );
    wc.style = 0;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 26 );
    wc.lpszMenuName = NULL;
    wc.lpszClassName = NazwaKlasy;
    wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
   
    // REJESTROWANIE KLASY OKNA
    if( !RegisterClassEx( & wc ) )
    {
        MessageBox( NULL, "Wysoka Komisja odmawia rejestracji tego okna!", "Niestety...", MB_ICONEXCLAMATION | MB_OK );
        return 1;
    }
   
    // TWORZENIE OKNA
    HWND hwnd;
    hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, "Kalkulator", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, hInstance, NULL );
    HWND hButton1 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "7", WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 40, 40, hwnd,( HMENU ) ID_PRZYCISK7, hInstance, NULL ),
    hButton2 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "4", WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 100, 40, 40, hwnd,( HMENU ) ID_PRZYCISK4, hInstance, NULL ),
    hButton3 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "1", WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 150, 40, 40, hwnd,( HMENU ) ID_PRZYCISK1, hInstance, NULL ),
    hButton4 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "8", WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 50, 40, 40, hwnd,( HMENU ) ID_PRZYCISK8, hInstance, NULL ),
    hButton5 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "5", WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 100, 40, 40, hwnd,( HMENU ) ID_PRZYCISK5, hInstance, NULL ),
    hButton6 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "2", WS_CHILD | WS_VISIBLE | WS_BORDER, 100, 150, 40, 40, hwnd,( HMENU ) ID_PRZYCISK2, hInstance, NULL ),
    hButton7 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "9", WS_CHILD | WS_VISIBLE | WS_BORDER, 150, 50, 40, 40, hwnd,( HMENU ) ID_PRZYCISK9, hInstance, NULL ),
    hButton8 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "6", WS_CHILD | WS_VISIBLE | WS_BORDER, 150, 100, 40, 40, hwnd,( HMENU ) ID_PRZYCISK6, hInstance, NULL ),
    hButton9 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "3", WS_CHILD | WS_VISIBLE | WS_BORDER, 150, 150, 40, 40, hwnd,( HMENU ) ID_PRZYCISK3, hInstance, NULL ),
    hFrame = CreateWindowEx( 0, "BUTTON", "Numbers", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 30, 30, 180, 180, hwnd,( HMENU ) ID_FRAME, hInstance, NULL ),
    hFrame1 = CreateWindowEx( 0, "BUTTON", "Numbers", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 210, 30, 180, 180, hwnd,( HMENU ) ID_FRAME1, hInstance, NULL ),
    hFrame2 = CreateWindowEx( 0, "BUTTON", "Numbers", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 370, 30, 180, 180, hwnd,( HMENU ) ID_FRAME2, hInstance, NULL );
    SendMessage( hButton1, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton2, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton3, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton4, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton5, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton6, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton7, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton8, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton9, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hFrame, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hFrame1, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hFrame2, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
   
    if( hwnd == NULL )
    {
        MessageBox( NULL, "Okno odmówi³o przyjœcia na œwiat!", "Ale kicha...", MB_ICONEXCLAMATION );
        return 1;
    }
   
    ShowWindow( hwnd, nCmdShow ); // Poka¿ okienko...
    UpdateWindow( hwnd );
   
    // Pêtla komunikatów
    while( GetMessage( & Komunikat, NULL, 0, 0 ) )
    {
        TranslateMessage( & Komunikat );
        DispatchMessage( & Komunikat );
    }
    return Komunikat.wParam;
}
Według Kursu WinAPI na tej stronie.
P-129301
pekfos
» 2015-03-28 11:27:09
Linkujesz gdi32?
P-129305
sppmacd
Temat założony przez niniejszego użytkownika
» 2015-05-23 11:06:37
Teraz nie ma już tego problemu, przerzuciłem się na inny komputer z Win8 i wszystko działa jak należy. Dziękuję za pomoc!

Zmieniłem też kod, ale jest podobny do poprzedniego, jest to tym razem tester funkcji WinAPI:

C/C++
#include <windows.h>

#define ID_PRZYCISK1 501
#define ID_PRZYCISK2 502
#define ID_PRZYCISK3 503
#define ID_PRZYCISK4 504
#define ID_PRZYCISK5 505

HFONT hNormalFont =( HFONT ) GetStockObject( DEFAULT_GUI_FONT );
LPSTR NazwaKlasy = " ";
MSG Komunikat;

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
   
    // WYPE£NIANIE STRUKTURY
    WNDCLASSEX wc;
   
    wc.cbSize = sizeof( WNDCLASSEX );
    wc.style = 0;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
    wc.lpszMenuName = NULL;
    wc.lpszClassName = NazwaKlasy;
    wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
   
    // REJESTROWANIE KLASY OKNA
    if( !RegisterClassEx( & wc ) )
   
    {
        MessageBox( NULL, "Blad rejestracji okna!", "UWAGA!",
        MB_ICONEXCLAMATION | MB_OK );
        return 1;
    }
   
    // TWORZENIE OKNA
    HWND hwnd;
   
    hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, "Aplikacja okienkowa", WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768, NULL, NULL, hInstance, NULL );
   
    HWND hButton1 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "Uruchom &MessageBoxEx()", WS_CHILD | WS_VISIBLE |
    WS_BORDER, 50, 50, 300, 30, hwnd,( HMENU ) ID_PRZYCISK1, hInstance, NULL ),
   
    hFrame1 = CreateWindowEx( 0, "BUTTON", "Funkcje", WS_CHILD | WS_VISIBLE |
    WS_BORDER | BS_GROUPBOX, 40, 30, 320, 210, hwnd,( HMENU ) ID_PRZYCISK1, hInstance, NULL ),
   
    hFrame2 = CreateWindowEx( 0, "BUTTON", "Akcje programu", WS_CHILD | WS_VISIBLE |
    WS_BORDER | BS_GROUPBOX, 40, 239, 320, 60, hwnd,( HMENU ) ID_PRZYCISK1, hInstance, NULL ),
   
    hButton2 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "Uruchom &CreateWindow()", WS_CHILD | WS_VISIBLE |
    WS_BORDER, 50, 100, 300, 30, hwnd,( HMENU ) ID_PRZYCISK2, hInstance, NULL ),
   
    hButton3 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "Uruchom C&reateWindowEx()", WS_CHILD | WS_VISIBLE |
    WS_BORDER, 50, 150, 300, 30, hwnd,( HMENU ) ID_PRZYCISK3, hInstance, NULL ),
   
    hButton4 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "&Uruchom", WS_CHILD | WS_VISIBLE |
    WS_BORDER, 50, 200, 300, 30, hwnd,( HMENU ) ID_PRZYCISK4, hInstance, NULL ),
   
    hButton5 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "&Zamknij tester", WS_CHILD | WS_VISIBLE |
    WS_BORDER, 50, 260, 300, 30, hwnd,( HMENU ) ID_PRZYCISK5, hInstance, NULL );
   
    SendMessage( hButton1, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton2, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton3, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton4, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hButton5, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hFrame1, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
    SendMessage( hFrame2, WM_SETFONT,( WPARAM ) hNormalFont, 0 );
   
   
    if( hwnd == NULL )
    {
        MessageBox( NULL, "Okno nie moze powstac", "UWAGA!", MB_ICONEXCLAMATION );
        return 1;
    }
   
    ShowWindow( hwnd, nCmdShow ); // Poka¿ okienko...
    UpdateWindow( hwnd );
   
    // Pêtla komunikatów
    while( GetMessage( & Komunikat, NULL, 0, 0 ) )
    {
        TranslateMessage( & Komunikat );
        DispatchMessage( & Komunikat );
    }
    return Komunikat.wParam;
}

// OBS£UGA ZDARZEÑ
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
    case WM_CLOSE:
        DestroyWindow( hwnd );
        break;
       
    case WM_DESTROY:
        PostQuitMessage( 0 );
        break;
    case WM_COMMAND:
        switch( wParam )
        {
        case ID_PRZYCISK1:
            MessageBoxEx( hwnd, "Test funkcji MessageBoxEx()", "AplikacjaOkienkowa_Main", MB_ICONINFORMATION, WM_CUT );
            break;
           
        case ID_PRZYCISK5:
            DestroyWindow( hwnd );
            return DefWindowProc( hwnd, msg, wParam, lParam );
            break;
           
            default:
            MessageBox( hwnd, "Zrobiles cos innego ;-)", "Test", MB_ICONINFORMATION );
        }
        break;
       
        default:
        return DefWindowProc( hwnd, msg, wParam, lParam );
    }
   
    return 0;
}
P-132654
« 1 »
  Strona 1 z 1