ComCtl32.Lib not found; code doesn't work... Outdated again?

This is a discussion on ComCtl32.Lib not found; code doesn't work... Outdated again? within the Windows Programming forums, part of the Platform Specific Boards category; For the code below, I need to include "ComCtl32.Lib" which is supposed to be in my Visual Studio folder according ...

  1. #1
    Novice programmer newn's Avatar
    Join Date
    Aug 2010
    Posts
    59

    ComCtl32.Lib not found; code doesn't work... Outdated again?

    For the code below, I need to include "ComCtl32.Lib" which is supposed to be in my Visual Studio folder according to the tutorial. The tutorial was written for VS6, and I am using VS2010. I was unable to find the file, and when compiling the code below, I am getting some errors, which as far, as I understand, are because of the not included library file.
    My guess is - outdated tutorial again.
    Code:
    //---------------------------------------------------------------------------
    #include <windows.h>
    #include <commctrl.h>
    #include "resource.h"
    
    //---------------------------------------------------------------------------
    char AppCaption[40];
    HINSTANCE hInst;
    const int NUMBUTTONS = 7;
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
    			      WPARAM wParam, LPARAM lParam);
    //---------------------------------------------------------------------------
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine, int nCmdShow)
    {
    	MSG        Msg;
    	HWND       hWnd;
    	WNDCLASSEX WndClsEx;
        LPCTSTR ClsName = L"ResFund";
    
    	LoadString(hInstance, IDS_APP_NAME, AppCaption, 40);
    
    	hInst = hInstance;
    
    	// Create the application window
    	WndClsEx.cbSize        = sizeof(WNDCLASSEX);
    	WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
    	WndClsEx.lpfnWndProc   = WndProcedure;
    	WndClsEx.cbClsExtra    = 0;
    	WndClsEx.cbWndExtra    = 0;
    	WndClsEx.hIcon         = LoadIcon(hInstance,
    					  MAKEINTRESOURCE(IDI_RESFUND2));
    	WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
    	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	WndClsEx.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINFRAME);
    	WndClsEx.lpszClassName = ClsName;
    	WndClsEx.hInstance     = hInst;
    	WndClsEx.hIconSm       = LoadIcon(hInstance,
    					  MAKEINTRESOURCE(IDI_RESFUND2));
    
    	// Register the application
    	RegisterClassEx(&WndClsEx);
    
    	// Create the window object
    	hWnd = CreateWindowEx(0,
                              ClsName,
                              AppCaption,
                   		  WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT,
                   		  CW_USEDEFAULT,
                              CW_USEDEFAULT,
                   		  CW_USEDEFAULT,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    	
    	// Find out if the window was created
    	if( !hWnd ) // If the window was not created,
    		return FALSE; // stop the application
    
    	INITCOMMONCONTROLSEX InitCtrlEx;
    
    	InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    	InitCtrlEx.dwICC  = ICC_BAR_CLASSES;
    	InitCommonControlsEx(&InitCtrlEx);
    
    	TBBUTTON tbrButtons[7];
    	
    	tbrButtons[0].iBitmap   = 0;
    	tbrButtons[0].idCommand = IDM_FILE_NEW;
    	tbrButtons[0].fsState   = TBSTATE_ENABLED;
    	tbrButtons[0].fsStyle   = TBSTYLE_BUTTON;
    	tbrButtons[0].dwData    = 0L;
    	tbrButtons[0].iBitmap   = 0;
    	tbrButtons[0].iString   = 0;
    	
    	tbrButtons[1].iBitmap   = 1;
    	tbrButtons[1].idCommand = IDM_FILE_OPEN;
    	tbrButtons[1].fsState   = TBSTATE_ENABLED;
    	tbrButtons[1].fsStyle   = TBSTYLE_BUTTON;
    	tbrButtons[1].dwData    = 0L;
    	tbrButtons[1].iString   = 0;
    
    	tbrButtons[2].iBitmap   = 0;
    	tbrButtons[2].idCommand = 0;
    	tbrButtons[2].fsState   = TBSTATE_ENABLED;
    	tbrButtons[2].fsStyle   = TBSTYLE_SEP;
    	tbrButtons[2].dwData    = 0L;
    	tbrButtons[2].iString   = 0;
    
    	tbrButtons[3].iBitmap   = 2;
    	tbrButtons[3].idCommand = IDM_ARROW;
    	tbrButtons[3].fsState   = TBSTATE_ENABLED;
    	tbrButtons[3].fsStyle   = TBSTYLE_BUTTON;
    	tbrButtons[3].dwData    = 0L;
    	tbrButtons[3].iString   = 0;
    
    	tbrButtons[4].iBitmap   = 3;
    	tbrButtons[4].idCommand = IDM_DRAW_LINE;
    	tbrButtons[4].fsState   = TBSTATE_ENABLED;
    	tbrButtons[4].fsStyle   = TBSTYLE_BUTTON;
    	tbrButtons[4].dwData    = 0L;
    	tbrButtons[4].iString   = 0;
    
    	tbrButtons[5].iBitmap   = 4;
    	tbrButtons[5].idCommand = IDM_DRAW_RECTANGLE;
    	tbrButtons[5].fsState   = TBSTATE_ENABLED;
    	tbrButtons[5].fsStyle   = TBSTYLE_BUTTON;
    	tbrButtons[5].dwData    = 0L;
    	tbrButtons[5].iString   = 0;
    	
    	tbrButtons[6].iBitmap   = 5;
    	tbrButtons[6].idCommand = IDM_DRAW_ELLIPSE;
    	tbrButtons[6].fsState   = TBSTATE_ENABLED;
    	tbrButtons[6].fsStyle   = TBSTYLE_BUTTON;
    	tbrButtons[6].dwData    = 0L;
    	tbrButtons[6].iString   = 0;
    
    	HWND hWndToolbar;
    	hWndToolbar = CreateToolbarEx(hWnd,
    		                      WS_VISIBLE | WS_CHILD | WS_BORDER,
    	                              IDB_STANDARD,
    	                              NUMBUTTONS,
    				      hInst,
    			              IDB_STANDARD,
    				      tbrButtons,
    				      NUMBUTTONS,
    				      16, 16, 16, 16,
    				      sizeof(TBBUTTON));
    
    	// Display the window to the user
    	ShowWindow(hWnd, nCmdShow);
    	UpdateWindow(hWnd);
    
    	// Decode and treat the messages
    	// as long as the application is running
    	while( GetMessage(&Msg, NULL, 0, 0) )
    	{
                 TranslateMessage(&Msg);
                 DispatchMessage(&Msg);
    	}
    
        return 0;
    }
    //---------------------------------------------------------------------------
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
    			   WPARAM wParam, LPARAM lParam)
    {
        switch(Msg)
        {
        case WM_DESTROY:
            PostQuitMessage(WM_QUIT);
            break;
        default:
            // Process the left-over messages
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        // If something was not done, let it go
        return 0;
    }
    //---------------------------------------------------------------------------
    1>------ Build started: Project: Introduction to Resources, Configuration: Debug Win32 ------
    1>Build started 4/18/2011 5:27:37 PM.
    1>InitializeBuildStatus:
    1> Touching "Debug\Introduction to Resources.unsuccessfulbuild".
    1>ClCompile:
    1> main.cpp
    1>ResourceCompile:
    1> All outputs are up-to-date.
    1>ManifestResourceCompile:
    1> All outputs are up-to-date.
    1>main.obj : error LNK2019: unresolved external symbol __imp__CreateToolbarEx@52 referenced in function _WinMain@16
    1>main.obj : error LNK2019: unresolved external symbol __imp__InitCommonControlsEx@4 referenced in function _WinMain@16
    1>D:\Backup\C++\Win32\Introduction to Resources\Debug\Introduction to Resources.exe : fatal error LNK1120: 2 unresolved externals
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:01.51
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    P.S. Where can I find a decent tutorial (with good explanations), which isn't outdated (works alright with VS2010)?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That's a linker error... you need to add the library to the linker settings in your project...

  3. #3
    Novice programmer newn's Avatar
    Join Date
    Aug 2010
    Posts
    59
    Exactly what I thought.
    And as I said - there is no such library, because, most likely, this one is outdated and not being used anymore with the modern Visual Studio.
    What do I need to include to make this code work with VS2010?

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by newn View Post
    Exactly what I thought.
    And as I said - there is no such library, because, most likely, this one is outdated and not being used anymore with the modern Visual Studio.
    What do I need to include to make this code work with VS2010?
    Ummm... comctl32.lib and comctl32.dll are current files. I have both in my setup (Pelles C)...

    This is clearly an error...
    Check in your windows libraries folders...
    As a last resort uninstall and reinstall visual studio.

    Also note, there are several versions of VS... make sure you've got the C++ version...

    Or, if you're working plain C... grab a copy of PellesC ... it is a better setup, it's free, and it has better resource tools than VS does.
    Last edited by CommonTater; 04-18-2011 at 10:54 AM.

  5. #5
    Novice programmer newn's Avatar
    Join Date
    Aug 2010
    Posts
    59
    The file must be somewhere, I guess in... Windows libraries folder, wherever it might be...
    This line makes the program to work:
    Code:
    #pragma comment(lib, "comctl32.lib")

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by newn View Post
    The file must be somewhere, I guess in... Windows libraries folder, wherever it might be...
    This line makes the program to work:
    Code:
    #pragma comment(lib, "comctl32.lib")
    That does what I suggested earlier... adds the file to your linker's list.
    The prgama is fine, I use them all the time (but wasn't sure if VS supported them).
    Perhaps you should locate that file and update your search paths in VS.

    Glad it's working.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Example Code doesn't work!
    By Kayl669 in forum C Programming
    Replies: 8
    Last Post: 02-18-2010, 10:19 AM
  2. Using wrapping code icon doesn't work?
    By Aia in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 02-03-2008, 06:15 AM
  3. Simple C++ code doesn't work
    By alex_dude_122 in forum C++ Programming
    Replies: 6
    Last Post: 10-18-2006, 01:53 PM
  4. this code doesn't work please help me debug
    By newcstudent in forum C Programming
    Replies: 2
    Last Post: 10-09-2006, 06:01 AM
  5. this code compiles, but doesn't work how it should
    By Leeman_s in forum C++ Programming
    Replies: 10
    Last Post: 09-10-2002, 06:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21