CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Mar 2011
    Posts
    144

    [SOLVED]TCHAR correct usage

    Hello, I'm trying to get a Browse Directory dialog to update a text box with the path selected. I had it working fine in Unicode build but now using TCHAR - I see the variable contains the correct path, but the textbox only gets updated with a single weird character. Any help would be great, thanks.

    setting the text checking WM_COMMAND vars-
    Code:
    SetWindowText(textBox2,&buttonPush(hWnd));
    browse function when Browse button is pressed -
    Code:
    TCHAR& buttonPush(HWND hWnd) {
    		BROWSEINFO bi;
       TCHAR szDir[MAX_PATH];
       LPITEMIDLIST pidl;
       LPMALLOC pMalloc;
    
       if (SUCCEEDED(SHGetMalloc(&pMalloc)))
       {
          ZeroMemory(&bi,sizeof(bi));
          bi.hwndOwner = hWnd;
          bi.pszDisplayName = 0;
          bi.pidlRoot = 0;
          bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_USENEWUI | BIF_NONEWFOLDERBUTTON;
    	  bi.pszDisplayName = szDir; // Address of a buffer to receive the display name of the folder selected by the user
    		bi.lpszTitle = _T("Select a folder "); // Title of the dialog
    
          bi.lpfn = BrowseCallbackProc;
    	pidl = SHBrowseForFolder(&bi); 
    		
    		if (pidl) 
    		{ 
    			// Folder selected in dialog
    			TCHAR szReturnedDir[_MAX_PATH];
    
    			BOOL bRet = ::SHGetPathFromIDList(pidl, szReturnedDir);
    			if(bRet) return *szReturnedDir; // szReturnedDir holds the correct selected dir
    			pMalloc->Free(pidl); 
    		} 
    		pMalloc->Release();
        }
       return *szDir;
    }
    Last edited by drwbns; January 8th, 2013 at 08:54 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