CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2003
    Posts
    280

    Toolbar:undeclared identifier:BTNS_BUTTON,I_IMAGENONE,MAX_LEN

    Hello,
    OS: Win2000 , Compiler:MSCV 6.0
    I copy source code from MSDN:Using Toolbar...:
    Code:
    // CreateAToolBar creates a toolbar and adds a set of buttons to it.
    // The function returns the handle to the toolbar if successful, 
    // or NULL otherwise. 
    // hwndParent is the handle to the toolbar's parent window. 
    HWND CreateAToolBar(HWND hwndParent) 
    { 
       HWND hwndTB; 
       TBADDBITMAP tbab; 
       TBBUTTON tbb[3]; 
       char szBuf[16]; 
       int iCut, iCopy, iPaste;
       INITCOMMONCONTROLSEX icex;
       HRESULT hr;
       size_t cch;
    
    // Ensure that the common control DLL is loaded. 
       icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
       icex.dwICC  = ICC_BAR_CLASSES;
       InitCommonControlsEx(&icex);
    
    // Create a toolbar. 
       hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL, 
            WS_CHILD | CCS_ADJUSTABLE, 0, 0, 0, 0, hwndParent, 
            (HMENU) ID_TOOLBAR, g_hinst, NULL); 
    
    // Send the TB_BUTTONSTRUCTSIZE message, which is required for 
    // backward compatibility. 
       SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0); 
    
    // Add the button strings to the toolbar's internal string list. 
       LoadString(g_hinst, IDS_CUT, szBuf, MAX_LEN-1); 
    //Save room for second terminating null character.
       hr = StringCchLength(szBuf, MAX_LEN, &cch);
       if(SUCCEEDED(hr))
       {
       szBuf[cch + 2] = 0;  //Double-null terminate.
       }
       else
       {
       // TODO: Write error handler.
       } 
       iCut = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf); 
       LoadString(g_hinst, IDS_COPY, szBuf, MAX_LEN-1);  
    //Save room for second terminating null character.
       hr = StringCchLength(szBuf, MAX_LEN, &cch);
       if(SUCCEEDED(hr))
       {
       szBuf[cch + 2] = 0;  //Double-null terminate.
       }
       else
       {
       // TODO: Write error handler.
       } 
       iCopy = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0, 
           (LPARAM) (LPSTR) szBuf); 
       LoadString(g_hinst, IDS_PASTE, szBuf, MAX_LEN-1);  
    //Save room for second terminating null character.
       hr = StringCchLength(szBuf, MAX_LEN, &cch);
       if(SUCCEEDED(hr))
       {
       szBuf[cch + 2] = 0;  //Double-null terminate.
       }
       else
       {
       // TODO: Write error handler.
       } 
       iPaste = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0, 
            (LPARAM) (LPSTR) szBuf); 
     
    // Fill the TBBUTTON array with button information, and add the 
    // buttons to the toolbar. The buttons on this toolbar have text 
    // but do not have bitmap images. 
       tbb[0].iBitmap = I_IMAGENONE; 
       tbb[0].idCommand = IDS_CUT; 
       tbb[0].fsState = TBSTATE_ENABLED; 
       tbb[0].fsStyle = BTNS_BUTTON; 
       tbb[0].dwData = 0; 
       tbb[0].iString = iCut; 
     
       tbb[1].iBitmap = I_IMAGENONE; 
       tbb[1].idCommand = IDS_COPY; 
       tbb[1].fsState = TBSTATE_ENABLED; 
       tbb[1].fsStyle = BTNS_BUTTON; 
       tbb[1].dwData = 0; 
       tbb[1].iString = iCopy; 
    
       tbb[2].iBitmap = I_IMAGENONE; 
       tbb[2].idCommand = IDS_PASTE; 
       tbb[2].fsState = TBSTATE_ENABLED; 
       tbb[2].fsStyle = BTNS_BUTTON; 
       tbb[2].dwData = 0; 
       tbb[2].iString = iPaste; 
    
       SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS, 
            (LPARAM) (LPTBBUTTON) &tbb); 
    
       SendMessage(hwndTB, TB_AUTOSIZE, 0, 0); 
    
       ShowWindow(hwndTB, SW_SHOW); 
       return hwndTB; 
    }
    After compiling the source code,the compiler :
    Code:
    error C2065: 'MAX_LEN' : undeclared identifier
    warning C4013: 'StringCchLength' undefined; assuming extern returning int
    error C2065: 'I_IMAGENONE' : undeclared identifier
    error C2065: 'BTNS_BUTTON' : undeclared identifier
    How do I to define the undeclared identifier???
    To remove those undeclared idenfitifer and to build:
    unresolved external symbol _StringCchLength
    What 's wrong?
    Could someone help me explain???
    Thanks!

  2. #2
    Join Date
    Sep 2003
    Posts
    280
    I replace BTNS_BUTTON to TBSTYLE_BUTTON,I_IMAGENONE to -1 and define MAX_LEN as 128.
    But I don't know how to solve the "unresolved external symbol _StringCchLength".

  3. #3
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Add strsafe.lib in your linker settings or #pragma comment(lib,"strsafe")

    For those that read this that do not have strsafe.lib, or strsafe.h then download the latest platform SDK.

  4. #4
    Join Date
    Sep 2003
    Posts
    280
    Quote Originally Posted by Mick
    Add strsafe.lib in your linker settings or #pragma comment(lib,"strsafe")

    For those that read this that do not have strsafe.lib, or strsafe.h then download the latest platform SDK.
    Excuse me! Where to download the latest platform SDK?
    Thanks!

  5. #5
    Join Date
    Sep 2002
    Posts
    924
    Quote Originally Posted by Cooker
    Excuse me! Where to download the latest platform SDK?
    Thanks!
    http://www.microsoft.com/msdownload/...sdk/sdkupdate/

  6. #6
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Quote Originally Posted by Cooker
    Excuse me! Where to download the latest platform SDK?
    Thanks!
    I would have expected a different error if you did not have the SDK already installed. Then again...looking at the headers...that makes sense
    Last edited by Mick; August 21st, 2004 at 02:01 PM.

  7. #7
    Join Date
    Sep 2003
    Posts
    280
    Quote Originally Posted by Mick
    I would have expected a different error if you did not have the SDK already installed. Then again...looking at the headers...that makes sense
    Before updating the sdk:
    Code:
    Cannot open include file: 'strsafe.h': No such file or directory
    cannot open file "strsafe.lib"
    I temporarily replace StringCchLength by strlen.
    Last edited by Cooker; August 21st, 2004 at 09:19 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured