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

Threaded View

  1. #14
    Join Date
    Mar 2011
    Posts
    144

    Re: Capturing files in a directory

    dir is a StringVector like you suggested - but I'm getting a crash after calling buttonPush -

    Code:
    bool buttonPush(HWND hWnd, StringVector &dir ) {
    
    		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) 
    		{ 
    			BOOL bRet = ::SHGetPathFromIDList(pidl, const_cast<char *>(dir[0].c_str())); // dir gets a bad ptr here, how can I do this with a StringVector?
    			pMalloc->Free(pidl); 
    			pMalloc->Release();
    			if(bRet) return true;
    		} 
        }
       return false;
    }
    Code:
    SetWindowText(textBox2, const_cast<char *>(dir[0].c_str()));
    Is const casting safe to do in this scenario?
    Last edited by drwbns; January 10th, 2013 at 12:15 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