When compiling the example from MSDN the following error has place: LNK2019 unresolved external symbol reference

Евгений Бузин 1 Reputation point

Hi. I have a problem with creation of toolbar in Win32 C++ application. I want to reproduce an example from MSDN: https://learn.microsoft.com/en-us/windows/win32/controls/create-toolbars.
Below is source code:

HIMAGELIST g_hImageList = NULL;  
#define IDM_OPEN 1  
#define IDM_NEW   2  
#define IDM_SAVE   3  
HWND CreateSimpleToolbar(HWND hWndParent)  
    // Declare and initialize local constants.  
    const int ImageListID    = 0;  
    const int numButtons   = 3;  
    const int bitmapSize     = 16;  
    const DWORD buttonStyles = BTNS_AUTOSIZE;  
    // Create the toolbar.  
    HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,   
                                      WS_CHILD | TBSTYLE_WRAPABLE, 0, 0, 0, 0,   
                                      hWndParent, NULL, g_hInst, NULL);  
    if (hWndToolbar == NULL)  
        return NULL;  
    // Create the image list.  
    g_hImageList = ImageList_Create(bitmapSize, bitmapSize,   // Dimensions of individual bitmaps.  
                                    ILC_COLOR16 | ILC_MASK,   // Ensures transparent background.  
                                    numButtons, 0);  
    // Set the image list.  
    SendMessage(hWndToolbar, TB_SETIMAGELIST,   
    // Load the button images.  
    SendMessage(hWndToolbar, TB_LOADIMAGES,   
    // Initialize button info.  
    // IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants.  
    TBBUTTON tbButtons[numButtons] =   
        { MAKELONG(STD_FILENEW,  ImageListID), IDM_NEW,  TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },  
        { MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},  
        { MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0,               buttonStyles, {0}, 0, (INT_PTR)L"Save"}  
    // Add buttons.  
    SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);  
    SendMessage(hWndToolbar, TB_ADDBUTTONS,       (WPARAM)numButtons,       (LPARAM)&tbButtons);  
    // Resize the toolbar, and then show it.  
    SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);   
    ShowWindow(hWndToolbar,  TRUE);  
    return hWndToolbar;  

But when building the application, I get the following error: LNK2019 unresolved external symbol reference imp__ImageList_Create@20 in function "struct HWND * cdecl CreateToolbar(struct HWND *)" (?CreateToolbar@@YAPAUHWND__@@PAU1@@Z).

Why does it take place? Please help me fix it. Thanks in advance.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,507 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,623 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Castorix31 83,021 Reputation points

    Link with Comctl32.lib

    You can add at beginning :

    #pragma comment (lib, "comctl32")

  2. JL-4805 1 Reputation point

    INITCOMMONCONTROLSEX iccx = { sizeof(iccx) };
    iccx.dwICC = ICC_LINK_CLASS;
    if (!InitCommonControlsEx(&iccx))
    return FALSE;

    0 comments No comments

  3. RLWA32 42,796 Reputation points
        INITCOMMONCONTROLSEX iccx = { sizeof(iccx) };
        iccx.dwICC = ICC_WIN95_CLASSES;
        if (!InitCommonControlsEx(&iccx))
        return FALSE;

    Try this.