Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Error in builiding..

hey,
when i compile it generato no error. but only warnings. and whn i try to build exe it gave following errors....
plz help me... what is that...


Linking...
maintoolbar.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
Debug/toolbar.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

toolbar.exe - 2 error(s), 0 warning(s)

Comments

  • pingpongpingpong Posts: 937Member
    You need to add comctl32.lib to your project.

    Tip: whenever you use a Microsoft API and you get a link error, look it up in MSDN, usually they put the required lib file in the API help page.

    : hey,
    : when i compile it generato no error. but only warnings. and whn i try to build exe it gave following errors....
    : plz help me... what is that...
    :
    :
    : Linking...
    : maintoolbar.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
    : Debug/toolbar.exe : fatal error LNK1120: 1 unresolved externals
    : Error executing link.exe.
    :
    : toolbar.exe - 2 error(s), 0 warning(s)
    :
    :

  • innocent_boyinnocent_boy Posts: 35Member
    // this is main c file...

    #include

    #include

    #include "resource.h"

    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

    static char gszClassName[] = "MyWindowClass";
    static HINSTANCE ghInstance = NULL;
    HWND ghToolBar;



    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {

    WNDCLASSEX WndClass;
    HWND hwnd;
    MSG Msg;

    ghInstance = hInstance;

    WndClass.cbSize = sizeof(WNDCLASSEX);
    WndClass.style = NULL;
    WndClass.lpfnWndProc = WndProc;
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;
    WndClass.hInstance = ghInstance;
    WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    WndClass.lpszMenuName = NULL;
    WndClass.lpszClassName = gszClassName;
    WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&WndClass)) {
    MessageBox(0, "Window Registration Failed!", "Error!", MB_ICONSTOP | MB_OK);
    return 0;
    }

    hwnd = CreateWindowEx(
    WS_EX_STATICEDGE,
    gszClassName,
    "Windows Title",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT,
    320, 240,
    NULL, NULL,
    ghInstance,
    NULL);

    if(hwnd == NULL) {
    MessageBox(0, "Window Creation Failed!", "Error!", MB_ICONSTOP | MB_OK);
    return 0;
    }


    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0)) {
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
    }
    return Msg.wParam;
    }

    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    TBADDBITMAP tbAddBitmap;
    TBBUTTON tbButton[8];


    switch(Message) {
    case WM_CREATE:


    InitCommonControls();

    ghToolBar = CreateWindowEx(
    NULL,
    TOOLBARCLASSNAME,
    NULL,
    WS_CHILD | WS_VISIBLE,
    0, 0,
    0, 0,
    hwnd, (HMENU)IDR_TOOLBAR1,
    ghInstance,
    NULL);
    SendMessage(ghToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), (LPARAM)NULL);

    tbAddBitmap.hInst = ghInstance;
    tbAddBitmap.nID = IDR_TOOLBAR1;
    SendMessage(ghToolBar, TB_ADDBITMAP, 6, (LPARAM) &tbAddBitmap);

    ZeroMemory(tbButton, sizeof(tbButton));

    tbButton[0].iBitmap = 0;
    tbButton[0].fsState = TBSTATE_ENABLED;
    tbButton[0].fsStyle = TBSTYLE_BUTTON;
    tbButton[0].idCommand = ID_BUTTON40001;

    tbButton[1].iBitmap = 1;
    tbButton[1].fsState = TBSTATE_ENABLED;
    tbButton[1].fsStyle = TBSTYLE_BUTTON;
    tbButton[1].idCommand = ID_BUTTON40002;

    tbButton[2].fsStyle = TBSTYLE_SEP;

    tbButton[3].iBitmap = 2;
    tbButton[3].fsState = TBSTATE_ENABLED;
    tbButton[3].fsStyle = TBSTYLE_BUTTON;
    tbButton[3].idCommand = ID_BUTTON40003;

    tbButton[4].iBitmap = 3;
    tbButton[4].fsState = TBSTATE_ENABLED;
    tbButton[4].fsStyle = TBSTYLE_BUTTON;
    tbButton[4].idCommand = ID_BUTTON40004;

    tbButton[5].fsStyle = TBSTYLE_SEP;

    /* tbButton[6].iBitmap = 4;
    tbButton[6].fsState = TBSTATE_ENABLED;
    tbButton[6].fsStyle = TBSTYLE_BUTTON;
    tbButton[6].idCommand = IDM_BUTTON4;

    tbButton[7].iBitmap = 5;
    tbButton[7].fsState = TBSTATE_ENABLED;
    tbButton[7].fsStyle = TBSTYLE_BUTTON;
    tbButton[7].idCommand = IDM_BUTTON5;
    */
    SendMessage(ghToolBar, TB_ADDBUTTONS, 8, (LPARAM) &tbButton);
    break;
    case WM_COMMAND:
    switch(LOWORD(wParam)) {
    case ID_BUTTON40001:
    case ID_BUTTON40002:
    case ID_BUTTON40003:
    case ID_BUTTON40004:
    /* case IDM_BUTTON4:
    case IDM_BUTTON5:*/
    MessageBox(hwnd, "A Button was clicked.", "Toolbar Message", MB_ICONINFORMATION | MB_OK);
    break;
    }
    break;
    case WM_SIZE:
    SendMessage(ghToolBar, TB_AUTOSIZE, 0, 0);
    break;
    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd, Message, wParam, lParam);
    }
    return 0;
    }

    //
    // Used by rc.rc
    //
    #define IDR_TOOLBAR1 101
    #define ID_BUTTON40001 40001
    #define ID_BUTTON40002 40002
    #define ID_BUTTON40003 40003
    #define ID_BUTTON40004 40004

    // Next default values for new objects


    /////////////////////////////////////////////////////////////////////////////
    //
    // Toolbar
    //

    IDR_TOOLBAR1 TOOLBAR DISCARDABLE 16, 15
    BEGIN
    BUTTON ID_BUTTON40001
    BUTTON ID_BUTTON40002
    BUTTON ID_BUTTON40003
    BUTTON ID_BUTTON40004
    END


    /////////////////////////////////////////////////////////////////////////////
    //
    // Bitmap
    //

    IDR_TOOLBAR1 BITMAP DISCARDABLE "toolbar1.bmp"


    and now tell me what is the problem with this code... it generates one error i mentioned in previous post.

    thanx..
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [blue]AGAIN, as [b]pingpong[/b] mentioned...

    [red][b]You need to add comctl32.lib to your project.[/b][/red]

    If you are using VC++, then go: Project - Settings - 'Link' tab - category 'General' or 'Input' - in the box called 'Object/library modules:' add the "comctl32.lib" and separate it from others with a blank. Click OK. Rebuild.

    In case you have some other compiler - check its manual on how to add a library to link with.[/blue]
  • xkgdiamxkgdiam Posts: 111Member
    [code]
    : // this is main c file...
    :
    : #include
    :
    : #include
    :
    : #include "resource.h"
    :
    : LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    :
    : static char gszClassName[] = "MyWindowClass";
    : static HINSTANCE ghInstance = NULL;
    : HWND ghToolBar;
    :
    :
    :
    : int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    : {
    :
    : WNDCLASSEX WndClass;
    : HWND hwnd;
    : MSG Msg;
    :
    : ghInstance = hInstance;
    :
    : WndClass.cbSize = sizeof(WNDCLASSEX);
    : WndClass.style = NULL;
    : WndClass.lpfnWndProc = WndProc;
    : WndClass.cbClsExtra = 0;
    : WndClass.cbWndExtra = 0;
    : WndClass.hInstance = ghInstance;
    : WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    : WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    : WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    : WndClass.lpszMenuName = NULL;
    : WndClass.lpszClassName = gszClassName;
    : WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    :
    : if(!RegisterClassEx(&WndClass)) {
    : MessageBox(0, "Window Registration Failed!", "Error!", MB_ICONSTOP | MB_OK);
    : return 0;
    : }
    :
    : hwnd = CreateWindowEx(
    : WS_EX_STATICEDGE,
    : gszClassName,
    : "Windows Title",
    : WS_OVERLAPPEDWINDOW,
    : CW_USEDEFAULT, CW_USEDEFAULT,
    : 320, 240,
    : NULL, NULL,
    : ghInstance,
    : NULL);
    :
    : if(hwnd == NULL) {
    : MessageBox(0, "Window Creation Failed!", "Error!", MB_ICONSTOP | MB_OK);
    : return 0;
    : }
    :
    :
    : ShowWindow(hwnd, nCmdShow);
    : UpdateWindow(hwnd);
    :
    : while(GetMessage(&Msg, NULL, 0, 0)) {
    : TranslateMessage(&Msg);
    : DispatchMessage(&Msg);
    : }
    : return Msg.wParam;
    : }
    :
    : LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    : {
    : TBADDBITMAP tbAddBitmap;
    : TBBUTTON tbButton[8];
    :
    :
    : switch(Message) {
    : case WM_CREATE:
    :
    :
    : [b]InitCommonControls();[/b]
    :
    : ghToolBar = CreateWindowEx(
    : NULL,
    : TOOLBARCLASSNAME,
    : NULL,
    : WS_CHILD | WS_VISIBLE,
    : 0, 0,
    : 0, 0,
    : hwnd, (HMENU)IDR_TOOLBAR1,
    : ghInstance,
    : NULL);
    : SendMessage(ghToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), (LPARAM)NULL);
    :
    : tbAddBitmap.hInst = ghInstance;
    : tbAddBitmap.nID = IDR_TOOLBAR1;
    : SendMessage(ghToolBar, TB_ADDBITMAP, 6, (LPARAM) &tbAddBitmap);
    :
    : ZeroMemory(tbButton, sizeof(tbButton));
    :
    : tbButton[0].iBitmap = 0;
    : tbButton[0].fsState = TBSTATE_ENABLED;
    : tbButton[0].fsStyle = TBSTYLE_BUTTON;
    : tbButton[0].idCommand = ID_BUTTON40001;
    :
    : tbButton[1].iBitmap = 1;
    : tbButton[1].fsState = TBSTATE_ENABLED;
    : tbButton[1].fsStyle = TBSTYLE_BUTTON;
    : tbButton[1].idCommand = ID_BUTTON40002;
    :
    : tbButton[2].fsStyle = TBSTYLE_SEP;
    :
    : tbButton[3].iBitmap = 2;
    : tbButton[3].fsState = TBSTATE_ENABLED;
    : tbButton[3].fsStyle = TBSTYLE_BUTTON;
    : tbButton[3].idCommand = ID_BUTTON40003;
    :
    : tbButton[4].iBitmap = 3;
    : tbButton[4].fsState = TBSTATE_ENABLED;
    : tbButton[4].fsStyle = TBSTYLE_BUTTON;
    : tbButton[4].idCommand = ID_BUTTON40004;
    :
    : tbButton[5].fsStyle = TBSTYLE_SEP;
    :
    : /* tbButton[6].iBitmap = 4;
    : tbButton[6].fsState = TBSTATE_ENABLED;
    : tbButton[6].fsStyle = TBSTYLE_BUTTON;
    : tbButton[6].idCommand = IDM_BUTTON4;
    :
    : tbButton[7].iBitmap = 5;
    : tbButton[7].fsState = TBSTATE_ENABLED;
    : tbButton[7].fsStyle = TBSTYLE_BUTTON;
    : tbButton[7].idCommand = IDM_BUTTON5;
    : */
    : SendMessage(ghToolBar, TB_ADDBUTTONS, 8, (LPARAM) &tbButton);
    : break;
    : case WM_COMMAND:
    : switch(LOWORD(wParam)) {
    : case ID_BUTTON40001:
    : case ID_BUTTON40002:
    : case ID_BUTTON40003:
    : case ID_BUTTON40004:
    : /* case IDM_BUTTON4:
    : case IDM_BUTTON5:*/
    : MessageBox(hwnd, "A Button was clicked.", "Toolbar Message", MB_ICONINFORMATION | MB_OK);
    : break;
    : }
    : break;
    : case WM_SIZE:
    : SendMessage(ghToolBar, TB_AUTOSIZE, 0, 0);
    : break;
    : case WM_CLOSE:
    : DestroyWindow(hwnd);
    : break;
    : case WM_DESTROY:
    : PostQuitMessage(0);
    : break;
    : default:
    : return DefWindowProc(hwnd, Message, wParam, lParam);
    : }
    : return 0;
    : }
    :
    : //
    : // Used by rc.rc
    : //
    : #define IDR_TOOLBAR1 101
    : #define ID_BUTTON40001 40001
    : #define ID_BUTTON40002 40002
    : #define ID_BUTTON40003 40003
    : #define ID_BUTTON40004 40004
    :
    : // Next default values for new objects
    :
    :
    : /////////////////////////////////////////////////////////////////////////////
    : //
    : // Toolbar
    : //
    :
    : IDR_TOOLBAR1 TOOLBAR DISCARDABLE 16, 15
    : BEGIN
    : BUTTON ID_BUTTON40001
    : BUTTON ID_BUTTON40002
    : BUTTON ID_BUTTON40003
    : BUTTON ID_BUTTON40004
    : END
    :
    :
    : /////////////////////////////////////////////////////////////////////////////
    : //
    : // Bitmap
    : //
    :
    : IDR_TOOLBAR1 BITMAP DISCARDABLE "toolbar1.bmp"
    :
    :
    : and now tell me what is the problem with this code... it generates one error i mentioned in previous post.
    :
    : thanx..
    :
    [/code]
  • innocent_boyinnocent_boy Posts: 35Member
    hey, now i have made tool bar .. but oh there is 5 buttons as i require but those are empty there is no bitmap visible.. how can do make tool bar with bitmap..
    You can view gif print of error.. here.. http://www.geocities.com/innocent4nu/toolbar.GIF

    i use the following code to make and load bitmap..

    case WM_CREATE:
    InitCommonControls();
    LoadBitmap(ghInstance,MAKEINTRESOURCE(IDR_TOOLBAR1));
    ghToolBar = CreateWindowEx(
    NULL,
    TOOLBARCLASSNAME,
    NULL,
    WS_CHILD | WS_VISIBLE,
    0, 0,
    0, 0,
    hwnd, (HMENU)IDR_TOOLBAR1,
    ghInstance,
    NULL);

    SendMessage(ghToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)
    sizeof(TBBUTTON), (LPARAM)NULL);

    tbAddBitmap.hInst = ghInstance;
    tbAddBitmap.nID = IDR_TOOLBAR1;

    SendMessage(ghToolBar, TB_ADDBITMAP, 6, (LPARAM) &tbAddBitmap);

    ZeroMemory(tbButton, sizeof(tbButton));//fills a block of
    memory with zeros.

    tbButton[0].iBitmap = 0;
    tbButton[0].fsState = TBSTATE_ENABLED;
    tbButton[0].fsStyle = TBSTYLE_BUTTON;
    tbButton[0].idCommand = ID_BUTTON40006;

    tbButton[1].iBitmap = 1;
    tbButton[1].fsState = TBSTATE_ENABLED;
    tbButton[1].fsStyle = TBSTYLE_BUTTON;
    tbButton[1].idCommand = ID_BUTTON40007;

    tbButton[2].fsStyle = TBSTYLE_SEP;

    tbButton[3].iBitmap = 2;
    tbButton[3].fsState = TBSTATE_ENABLED;
    tbButton[3].fsStyle = TBSTYLE_BUTTON;
    tbButton[3].idCommand = ID_BUTTON40008;

    tbButton[4].iBitmap = 3;
    tbButton[4].fsState = TBSTATE_ENABLED;
    tbButton[4].fsStyle = TBSTYLE_BUTTON;
    tbButton[4].idCommand = ID_BUTTON40010;

    tbButton[5].fsStyle = TBSTYLE_SEP;

    tbButton[6].iBitmap = 4;
    tbButton[6].fsState = TBSTATE_ENABLED;
    tbButton[6].fsStyle = TBSTYLE_BUTTON;
    tbButton[6].idCommand = ID_BUTTON40011;


    sendMessage(ghToolBar, TB_ADDBUTTONS, 7, (LPARAM) &tbButton);

    break;
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [b][red]This message was edited by AsmGuru62 at 2003-12-11 7:10:5[/red][/b][hr]
    : hey, now i have made tool bar .. but oh there is 5 buttons as i require but those are empty there is no bitmap visible.. how can do make tool bar with bitmap..
    : You can view gif print of error.. here.. http://www.geocities.com/innocent4nu/toolbar.GIF
    :
    : i use the following code to make and load bitmap..
    : [code]
    : case WM_CREATE:
    : InitCommonControls();
    : [red][b]LoadBitmap(ghInstance,MAKEINTRESOURCE(IDR_TOOLBAR1));[/b][/red]
    [blue]You have to put the return value (HBITMAP) somewhere...
    i.e. attach it to the 'ghToolBar below'...[/blue]

    [red]HBITMAP h = LoadBitmap (...);[/red]

    : ghToolBar = CreateWindowEx(
    : NULL,
    : TOOLBARCLASSNAME,
    : NULL,
    : WS_CHILD | WS_VISIBLE,
    : 0, 0,
    : 0, 0,
    : hwnd, (HMENU)IDR_TOOLBAR1,
    : ghInstance,
    : NULL);
    :
    : SendMessage(ghToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)
    : sizeof(TBBUTTON), (LPARAM)NULL);
    :
    : tbAddBitmap.hInst = ghInstance;
    : tbAddBitmap.nID = IDR_TOOLBAR1;
    :
    : SendMessage(ghToolBar, TB_ADDBITMAP, 6, (LPARAM) &tbAddBitmap);
    :
    : ZeroMemory(tbButton, sizeof(tbButton));//fills a block of
    : memory with zeros.
    :
    : tbButton[0].iBitmap = 0;
    : tbButton[0].fsState = TBSTATE_ENABLED;
    : tbButton[0].fsStyle = TBSTYLE_BUTTON;
    : tbButton[0].idCommand = ID_BUTTON40006;
    :
    : tbButton[1].iBitmap = 1;
    : tbButton[1].fsState = TBSTATE_ENABLED;
    : tbButton[1].fsStyle = TBSTYLE_BUTTON;
    : tbButton[1].idCommand = ID_BUTTON40007;
    :
    : tbButton[2].fsStyle = TBSTYLE_SEP;
    :
    : tbButton[3].iBitmap = 2;
    : tbButton[3].fsState = TBSTATE_ENABLED;
    : tbButton[3].fsStyle = TBSTYLE_BUTTON;
    : tbButton[3].idCommand = ID_BUTTON40008;
    :
    : tbButton[4].iBitmap = 3;
    : tbButton[4].fsState = TBSTATE_ENABLED;
    : tbButton[4].fsStyle = TBSTYLE_BUTTON;
    : tbButton[4].idCommand = ID_BUTTON40010;
    :
    : tbButton[5].fsStyle = TBSTYLE_SEP;
    :
    : tbButton[6].iBitmap = 4;
    : tbButton[6].fsState = TBSTATE_ENABLED;
    : tbButton[6].fsStyle = TBSTYLE_BUTTON;
    : tbButton[6].idCommand = ID_BUTTON40011;
    :
    :
    : sendMessage(ghToolBar, TB_ADDBUTTONS, 7, (LPARAM) &tbButton);
    :
    : break;
    :
    [/code]


Sign In or Register to comment.