question

68981917 avatar image
0 Votes"
68981917 asked JL-4805 commented

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

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

 HINSTANCE hInst;
 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, 
                 (WPARAM)ImageListID, 
                 (LPARAM)g_hImageList);
    
     // Load the button images.
     SendMessage(hWndToolbar, TB_LOADIMAGES, 
                 (WPARAM)IDB_STD_SMALL_COLOR, 
                 (LPARAM)HINST_COMMCTRL);
    
     // 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-apic++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered RLWA32-6355 commented

Link with Comctl32.lib

You can add at beginning :

 #pragma comment (lib, "comctl32")


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have #pragma comment(lib, "comctl32.lib") and it compiles, however, I then receive the error:
1407 - Cannot find window class.
Any suggestions?

0 Votes 0 ·

At program startup call InitCommonControlsEx function. Make sure to correctly populate the INITCOMMONCONTROLSEX structure before making the function call.


0 Votes 0 ·

I have tried that to no avail.
This is a very strange issue. I have a sister application (liter version) in which this works as expected.
I can't understand why this library isn't loading.
Any other suggestions or possible explanations?

0 Votes 0 ·
Show more comments
JL-4805 avatar image
0 Votes"
JL-4805 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered JL-4805 commented
     INITCOMMONCONTROLSEX iccx = { sizeof(iccx) };
     iccx.dwICC = ICC_WIN95_CLASSES;
     if (!InitCommonControlsEx(&iccx))
     {
     return FALSE;
     }


Try this.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That still doesn't do the trick.
This is a weird situation. I think I will just rebuild the entire project.
Thanks for your time and suggestions.

0 Votes 0 ·