CString Directories::browseForDir(CString title)
{
  static char buffer[1024];
  LPMALLOC pMalloc;
  LPITEMIDLIST pidl;
  
  CString res;
  
  if(SUCCEEDED(SHGetMalloc(&pMalloc))) {
    BROWSEINFO bi;
    ZeroMemory(&bi, sizeof(bi));
    bi.hwndOwner = m_hWnd;
    bi.lpszTitle = title;
    bi.pidlRoot = 0;
    bi.ulFlags = BIF_RETURNONLYFSDIRS;
    bi.lpfn = browseCallbackProc;
    bi.lParam = (LPARAM)(LPCTSTR)initialFolderDir;
    
    pidl = SHBrowseForFolder(&bi);
    
    if(pidl) {
      if(SHGetPathFromIDList(pidl, buffer)) {
        res = buffer;
      }
      pMalloc->Free(pidl);
      pMalloc->Release();
    }
  }
  return res;
}
Example #2
0
BOOL selectFolder(HWND hParent, WCHAR *szFolder)
{
	LPMALLOC pMalloc;
	LPITEMIDLIST pidl;
	BROWSEINFO bi;

	bi.hwndOwner = hParent;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = NULL;
	bi.lpszTitle = L"Select Folder to Save";
	bi.ulFlags = 0;
	bi.lpfn = NULL;
	bi.lParam = NULL;

	pidl = SHBrowseForFolder(&bi);

	if (pidl == NULL) {
		return FALSE;
	}
	SHGetPathFromIDList(pidl, szFolder);

	if (SHGetMalloc(&pMalloc) != NOERROR) {
		return FALSE;
	}
	pMalloc->Free(pidl);
	pMalloc->Release();
	return TRUE;
}
Example #3
0
wxString CLocalTreeView::GetSpecialFolder(int folder, int &iconIndex, int &openIconIndex)
{
	LPITEMIDLIST list;
	if (SHGetSpecialFolderLocation((HWND)GetHandle(), folder, &list) != S_OK)
		return _T("");

	SHFILEINFO shFinfo;
	if (!SHGetFileInfo((LPCTSTR)list, 0, &shFinfo, sizeof(shFinfo), SHGFI_PIDL | SHGFI_ICON | SHGFI_SMALLICON))
		return _T("");

	DestroyIcon(shFinfo.hIcon);
	iconIndex = shFinfo.iIcon;

	if (!SHGetFileInfo((LPCTSTR)list, 0, &shFinfo, sizeof(shFinfo), SHGFI_PIDL | SHGFI_ICON | SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_DISPLAYNAME))
		return _T("");

	DestroyIcon(shFinfo.hIcon);
	openIconIndex = shFinfo.iIcon;

	wxString name = shFinfo.szDisplayName;

	LPMALLOC pMalloc;
    SHGetMalloc(&pMalloc);

	if (pMalloc)
	{
		pMalloc->Free(list);
		pMalloc->Release();
	}
	else
		wxLogLastError(wxT("SHGetMalloc"));

	return name;
}
wyBool 
GetDirectoryFromUser(HWND hwnd, wyWChar *dirname, wyWChar *title)
{
	LPMALLOC		lpmalloc;
	BROWSEINFO		brwinf;
	LPITEMIDLIST	lpidl;

	memset(&brwinf, 0, sizeof(brwinf));

	if(SHGetMalloc(&lpmalloc)!= NOERROR)
		return wyFalse;

	brwinf.hwndOwner		= hwnd;
	brwinf.pidlRoot			= NULL;
	brwinf.pszDisplayName	= dirname;
	brwinf.lpszTitle		= title;
	brwinf.ulFlags			= BIF_EDITBOX | BIF_VALIDATE | BIF_NEWDIALOGSTYLE;

    //Displays a dialog box enabling the user to select a Shell folder
	lpidl = SHBrowseForFolder(&brwinf);

	if(!lpidl)
	{
		lpmalloc->Release();
		return wyFalse;
	}

    //Converts an item identifier list to a file system path
	SHGetPathFromIDList(lpidl, dirname);

	lpmalloc->Free(lpidl);
	lpmalloc->Release();

	return wyTrue;
}
Example #5
0
void COutputPage::OnBrowseFolder()
{
    TCHAR szPath[MAX_PATH];
    LPITEMIDLIST pPath;
    LPMALLOC pMalloc;
    BROWSEINFO pBI;

    ZeroMemory( &pBI, sizeof(pBI) );
    pBI.hwndOwner		= GetSafeHwnd();
    pBI.pszDisplayName	= szPath;
    pBI.lpszTitle		= _T("Select folder:");
    pBI.ulFlags			= BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;

    pPath = SHBrowseForFolder( &pBI );
    if ( pPath == NULL ) return;

    SHGetPathFromIDList( pPath, szPath );
    SHGetMalloc( &pMalloc );
    pMalloc->Free( pPath );
    pMalloc->Release();

    UpdateData( TRUE );
    m_sFolder = szPath;
    UpdateData( FALSE );
}
Example #6
0
BOOL PageSystem2::BrowseForFolder(HWND hOwner, TCHAR* szTitle, TCHAR* szRetval)
{
	BROWSEINFO info;
	LPITEMIDLIST itemidlist;
	TCHAR szDirectory[_MAX_PATH];
	LPMALLOC pMalloc;
	memset(szDirectory, 0, _MAX_PATH * sizeof(TCHAR));

	if (::SHGetMalloc(&pMalloc) == NOERROR)
	{
		info.hwndOwner = hOwner;
		info.pidlRoot = NULL;
		info.pszDisplayName = szDirectory;
		info.lpszTitle = szTitle;
		info.ulFlags = 0;
		info.lpfn = NULL;

		itemidlist = SHBrowseForFolder(&info);
		if (itemidlist != NULL)
		{
			SHGetPathFromIDList(itemidlist, szRetval);
			pMalloc->Free(itemidlist);
			pMalloc->Release();
			return TRUE;
		}
		else // User clicked Cancel
		{
			pMalloc->Release();
			return FALSE;
		}
	}
	else
		return FALSE;
}
Example #7
0
bool sspGUIfileDialogs::SelectFolder(HWND hOwner, const wchar_t* strTitle, CString& strFolder)
{
	bool bRet = false;

	BROWSEINFO brws = {0};
	wchar_t szName[260];       // buffer for file name
	szName[0] = 0;

	LPMALLOC pMalloc = NULL;
	SHGetMalloc(&pMalloc);

	brws.hwndOwner = hOwner;
	brws.pszDisplayName = szName;
	brws.lpszTitle = strTitle;
	brws.pidlRoot = NULL;
	brws.lpfn = NULL;
	brws.ulFlags = BIF_NONEWFOLDERBUTTON | BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN;
	LPITEMIDLIST pList = ::SHBrowseForFolder(&brws);
	if (::SHGetPathFromIDList(pList, szName)) {
		strFolder = szName;
		bRet = true;
	}
	if(pList) pMalloc->Free(pList);
	pMalloc->Release();
	return bRet;
}
Example #8
0
extern "C" void
GetSpecialDir(char *dst, size_t size, int whichDir)
{
    LPITEMIDLIST idl;
    LPMALLOC shl;
    char path[MAX_PATH + 1];
    HRESULT hResult;

    memset(dst, 0, size);
    hResult = SHGetMalloc(&shl);
    if (SUCCEEDED(hResult)) {
        hResult = SHGetSpecialFolderLocation(
                      NULL,
                      whichDir,
                      &idl
                  );

        if (SUCCEEDED(hResult)) {
            if(SHGetPathFromIDList(idl, path)) {
                (void) strncpy(dst, path, size - 1);
                dst[size - 1] = '\0';
            }
            shl->Free(idl);
        }
        shl->Release();
    }
}	// GetSpecialDir
Example #9
0
void CBrowseDirectory::BrowseDir(CString& retStr, CWnd* pFromWnd, LPCTSTR Title)
{
   LPMALLOC pMalloc;
   /* Get's the Shell's default allocator */
   if (NOERROR != ::SHGetMalloc(&pMalloc))
      AfxThrowMemoryException();

   BROWSEINFO bi;
   TCHAR pszBuffer[MAX_PATH];
   LPITEMIDLIST pidl;

   InitBrowseInfo(bi, pFromWnd, Title);
   bi.pszDisplayName = pszBuffer;
   // This next call issues the dialog box 
   __try
   {
      if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
	   {
	      __try
		   {
		      if (::SHGetPathFromIDList(pidl, pszBuffer))
			   { 
			      //At this point pszBuffer contains the selected path */
			      retStr = pszBuffer;
			   }
		   }
	      __finally
		   {
		      // Free the PIDL allocated by SHBrowseForFolder
		      pMalloc->Free(pidl);
		   }
	   }
   }
Example #10
0
void CProjectNew::OnProjectSelloc() 
{
	UpdateData(TRUE);

	BROWSEINFO bi;
	TCHAR szDir[MAX_PATH];
	LPITEMIDLIST pidl;
	LPMALLOC pMalloc;

	if (SUCCEEDED(SHGetMalloc(&pMalloc))) 
	{
		ZeroMemory(&bi,sizeof(bi));
		bi.hwndOwner = NULL;
		bi.pszDisplayName = 0;
		bi.pidlRoot = 0;
		bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
		bi.lpfn = BrowseCallbackProc;

		pidl = SHBrowseForFolder(&bi);
		if (pidl) 
		{
			if (SHGetPathFromIDList(pidl,szDir)) 
			{
				m_strProjectDir = szDir;
				UpdateData(FALSE);
			}

			// In C++: pMalloc->Free(pidl); pMalloc->Release();
			pMalloc->Free(pidl);
			pMalloc->Release();
		}
	}	
}
Example #11
0
bool Preferences::GetMyDocuments(CString* pPath)
{
    LPITEMIDLIST pidl = NULL;
    LPMALLOC lpMalloc = NULL;
    HRESULT hr;
    bool result = false;

    hr = ::SHGetMalloc(&lpMalloc);
    if (FAILED(hr))
       return NULL;

    hr = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl);
    if (FAILED(hr)) {
        LOGW("WARNING: unable to get CSIDL_PERSONAL");
        goto bail;
    }

    result = (Pidl::GetPath(pidl, pPath) != FALSE);
    if (!result) {
        LOGW("WARNING: unable to convert CSIDL_PERSONAL to path");
        /* fall through with "result" */
    }

bail:
    lpMalloc->Free(pidl);
    lpMalloc->Release();
    return result;
}
void CFileFindDlg::OnFolderbrowseBtn() 
{
	UpdateData(TRUE);
	BROWSEINFO bi;
	TCHAR szDir[MAX_PATH];
	
	LPMALLOC pMalloc;

	if (SUCCEEDED(SHGetMalloc(&pMalloc))) 
	{
		ZeroMemory(&bi,sizeof(bi));
		bi.hwndOwner = m_hWnd;
		bi.pszDisplayName = 0;
		bi.pidlRoot = 0;
		bi.ulFlags = BIF_RETURNONLYFSDIRS |/* BIF_STATUSTEXT | */BIF_EDITBOX | BIF_NEWDIALOGSTYLE;
		bi.lpfn = CFileFindDlg::BrowseCallbackProc;
		bi.lParam = (LPARAM)this;

		ITEMIDLIST* pidl = SHBrowseForFolder(&bi);
		if (pidl) 
		{
			if (SHGetPathFromIDList(pidl,szDir)) 
			{
				m_FindFolder = szDir;
				UpdateData(FALSE);
			}

			pMalloc->Free(pidl); 
			pMalloc->Release();
		}
	}
}
Example #13
0
//
//	フォルダー選択ダイアログの表示
//
//		結果は"c:\windows\"のように末尾に必ず"\"が付加する
//
bool CFolderSelect::Show(CString* lpstrFolder,CString strIniFolder,bool bAvailNewFolder)
{
	bool			ret;
	char			lpszPath[MAX_PATH];
	LPMALLOC		lpMalloc;
	BROWSEINFO		sInfo;
	LPITEMIDLIST	lpidlRoot;
	LPITEMIDLIST	lpidlBrowse;

	if(lpstrFolder == NULL)
		return	false;

	if(::SHGetMalloc(&lpMalloc) != NOERROR)
		return	false;

	ret = false;
	*lpstrFolder = "";
	if(strIniFolder != "")
	{
		if(strIniFolder.Right(1) == "\\")
			strIniFolder = strIniFolder.Left(strIniFolder.GetLength() - 1);			//末尾の\\を除去
	}

	::SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &lpidlRoot);	//選択可能フォルダ名取得

	::ZeroMemory(&sInfo, sizeof(BROWSEINFO));
	sInfo.pidlRoot		= lpidlRoot;
	sInfo.pszDisplayName = lpszPath;
	sInfo.lpszTitle		= _T("フォルダの選択");
	sInfo.ulFlags		= BIF_RETURNONLYFSDIRS;
	if(bAvailNewFolder == true)
		sInfo.ulFlags	|= BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_USENEWUI;
	sInfo.lpfn			= _SHBrowseForFolderCallbackProc;
	sInfo.lParam		= (LPARAM)strIniFolder.GetBuffer(0);

	lpidlBrowse = ::SHBrowseForFolder(&sInfo);			//フォルダ選択ダイアログ表示
	if(lpidlBrowse != NULL)
	{
		::SHGetPathFromIDList(lpidlBrowse,lpszPath);	//フォルダ名の取得
		*lpstrFolder = lpszPath;

		if(*lpstrFolder != "")
		{
			if(lpstrFolder->Right(1) != "\\")
				*lpstrFolder += "\\";			//末尾に\\が付加することを保証
		}

		ret = true;
	}

	if(lpidlBrowse != NULL)
		::CoTaskMemFree(lpidlBrowse);
	if(lpidlRoot != NULL)
		::CoTaskMemFree(lpidlRoot);

	lpMalloc->Release();

	return	ret;
}
generic_string folderBrowser(HWND parent, const generic_string & title, int outputCtrlID, const TCHAR *defaultStr)
{
	generic_string dirStr;

	// This code was copied and slightly modifed from:
	// http://www.bcbdev.com/faqs/faq62.htm

	// SHBrowseForFolder returns a PIDL. The memory for the PIDL is
	// allocated by the shell. Eventually, we will need to free this
	// memory, so we need to get a pointer to the shell malloc COM
	// object that will free the PIDL later on.
	LPMALLOC pShellMalloc = 0;
	if (::SHGetMalloc(&pShellMalloc) == NO_ERROR)
	{
		// If we were able to get the shell malloc object,
		// then proceed by initializing the BROWSEINFO stuct
		BROWSEINFO info;
		memset(&info, 0, sizeof(info));
		info.hwndOwner = parent;
		info.pidlRoot = NULL;
		TCHAR szDisplayName[MAX_PATH];
		info.pszDisplayName = szDisplayName;
		info.lpszTitle = title.c_str();
		info.ulFlags = 0;
		info.lpfn = BrowseCallbackProc;

		TCHAR directory[MAX_PATH];
		if (outputCtrlID != 0)
			::GetDlgItemText(parent, outputCtrlID, directory, _countof(directory));
		directory[_countof(directory) - 1] = '\0';

		if (!directory[0] && defaultStr)
			info.lParam = reinterpret_cast<LPARAM>(defaultStr);
		else
			info.lParam = reinterpret_cast<LPARAM>(directory);

		// Execute the browsing dialog.
		LPITEMIDLIST pidl = ::SHBrowseForFolder(&info);

		// pidl will be null if they cancel the browse dialog.
		// pidl will be not null when they select a folder.
		if (pidl)
		{
			// Try to convert the pidl to a display generic_string.
			// Return is true if success.
			TCHAR szDir[MAX_PATH];
			if (::SHGetPathFromIDList(pidl, szDir))
			{
				// Set edit control to the directory path.
				if (outputCtrlID != 0)
					::SetDlgItemText(parent, outputCtrlID, szDir);
				dirStr = szDir;
			}
			pShellMalloc->Free(pidl);
		}
		pShellMalloc->Release();
	}
	return dirStr;
}
Example #15
0
// Used (by getDeviceModes) to select a device
// so we can list its properties
static IBaseFilter* getDevFilter(QString devName)
{
    IBaseFilter* devFilter = nullptr;
    devName = devName.mid(6); // Remove the "video="
    IMoniker* m = nullptr;

    ICreateDevEnum* devenum = nullptr;
    if (CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, CLSCTX_INPROC_SERVER,
                             IID_ICreateDevEnum, (void**) &devenum) != S_OK)
        return devFilter;

    IEnumMoniker* classenum = nullptr;
    if (devenum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
                                (IEnumMoniker**)&classenum, 0) != S_OK)
        return devFilter;

    while (classenum->Next(1, &m, nullptr) == S_OK)
    {
        LPMALLOC coMalloc = nullptr;
        IBindCtx* bindCtx = nullptr;
        LPOLESTR olestr = nullptr;
        char* devIdString;

        if (CoGetMalloc(1, &coMalloc) != S_OK)
            goto fail;
        if (CreateBindCtx(0, &bindCtx) != S_OK)
            goto fail;

        if (m->GetDisplayName(bindCtx, nullptr, &olestr) != S_OK)
            goto fail;
        devIdString = wcharToUtf8(olestr);

        // replace ':' with '_' since FFmpeg uses : to delimitate sources
        for (unsigned i = 0; i < strlen(devIdString); i++)
            if (devIdString[i] == ':')
                devIdString[i] = '_';

        if (devName != devIdString)
            goto fail;

        if (m->BindToObject(0, 0, IID_IBaseFilter, (void**)&devFilter) != S_OK)
            goto fail;

fail:
        if (olestr && coMalloc)
            coMalloc->Free(olestr);
        if (bindCtx)
            bindCtx->Release();
        delete[] devIdString;
        m->Release();
    }
    classenum->Release();

    if (!devFilter)
        qWarning() << "Could't find the device "<<devName;

    return devFilter;
}
Example #16
0
//---------------------------------------------------------------------------
// RegisterServer
//---------------------------------------------------------------------------
BOOL RegisterServer(CLSID clsid, LPTSTR lpszTitle) {
  int      i;
  HKEY     hKey;
  LRESULT  lResult;
  DWORD    dwDisp;
  TCHAR    szSubKey[MAX_PATH];
  TCHAR    szCLSID[MAX_PATH];
  TCHAR    szModule[MAX_PATH];
  LPWSTR   pwsz;

  if (!CheckNpp()) {
    MsgBoxError(TEXT("To register the Notepad++ context menu extension,\r\ninstall nppcm.dll in the same directory than Notepad++.exe."));
    return FALSE;
  }

  StringFromIID(clsid, &pwsz);
  if(pwsz) {
#ifdef UNICODE
    lstrcpy(szCLSID, pwsz);
#else
    WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szCLSID, ARRAYSIZE(szCLSID), NULL, NULL);
#endif
    //free the string
    LPMALLOC pMalloc;
    CoGetMalloc(1, &pMalloc);
    pMalloc->Free(pwsz);
    pMalloc->Release();
  }

  //get this app's path and file name
  GetModuleFileName(_hModule, szModule, MAX_PATH);

  DOREGSTRUCT ClsidEntries[] = {
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s"),                              NULL,                   lpszTitle,
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),              NULL,                   szModule,
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),              TEXT("ThreadingModel"), TEXT("Apartment"),
    HKEY_CLASSES_ROOT,   TEXT("*\\shellex\\ContextMenuHandlers\\Notepad++"), NULL,                   szCLSID,
    NULL,                NULL,                                           NULL,                   NULL
  };

  // Register the CLSID entries
  for(i = 0; ClsidEntries[i].hRootKey; i++) {
    // Create the sub key string - for this case, insert the file extension
    wsprintf(szSubKey, ClsidEntries[i].szSubKey, szCLSID);
    lResult = RegCreateKeyEx(ClsidEntries[i].hRootKey, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
    if(NOERROR == lResult) {
      TCHAR szData[MAX_PATH];
      // If necessary, create the value string
      wsprintf(szData, ClsidEntries[i].szData, szModule);
      lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, REG_SZ, (LPBYTE)szData, (lstrlen(szData) + 1) * sizeof(TCHAR));
      RegCloseKey(hKey);
    }
    else
      return FALSE;
  }
  return TRUE;
}
Example #17
0
CString AfxGetDefaultDirectory(bool bForceNonEmpty /*= true*/,bool bNewProject /*= false*/)
{
	////////////////////////
	//Get default directory
	CString strPersonalDir;

	// - New Project?
	if (!bNewProject)
	{
		// - Get LastOpenedFolder
		strPersonalDir = CConfiguration::GetInstance()->m_strLastOpenedFolder;
		if (strPersonalDir.IsEmpty() || !CPathTool::Exists(strPersonalDir))
		{
			// - Project opened? ==> Working Dir is default
			CLaTeXProject* pLProject = theApp.GetProject();
			if (pLProject) strPersonalDir = pLProject->GetWorkingDirectory();
		}
	}

	// - No Project? ==> Try it with the default dir from the config
	if (strPersonalDir.IsEmpty())
	{
		strPersonalDir = CConfiguration::GetInstance()->m_strDefaultPath;
	}

	// - Still empty? ==> Get the system default for "My documents"
	if (strPersonalDir.IsEmpty())
	{
		LPITEMIDLIST lpidl;
		if (SHGetSpecialFolderLocation(AfxGetMainWnd()->m_hWnd,CSIDL_PERSONAL,&lpidl) == NOERROR)
		{
			SHGetPathFromIDList(lpidl,strPersonalDir.GetBuffer(MAX_PATH));
			strPersonalDir.ReleaseBuffer();

			// free memory
			LPMALLOC lpMalloc;
			SHGetMalloc(&lpMalloc);
			if (lpMalloc)
				lpMalloc->Free(lpidl);
		}
	}


	// - Still empty? ==> Hell, this is hard. Lets try this.
	if (bForceNonEmpty && strPersonalDir.IsEmpty())
	{
		strPersonalDir = theApp.GetWorkingDir();
	}

	// - Still empty? ==> Hell, this is hard. Lets try this.
	if (bForceNonEmpty && strPersonalDir.IsEmpty())
	{
		strPersonalDir = _T("C:\\");
	}

	return strPersonalDir;
}
/////////////////////////////////////////////////////////////////////////
//THIS FUNCTION IS TO SELECT THE PATH FOR SAVE THE DATA
/////////////////////////////////////////////////////////////////////////
void CNormalSettingDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	CString strResult =""; 
    LPMALLOC lpMalloc;  // POINTER TO IMALLOC 
    if (::SHGetMalloc(&lpMalloc) != NOERROR) 
	{ 
		AfxMessageBox("PATH OPERATION ERROR!"); 
		return ; 
	} 

    char szDisplayName[_MAX_PATH]; 
    char szBuffer[_MAX_PATH]; 
    BROWSEINFO browseInfo; 
    browseInfo.hwndOwner = this->m_hWnd; 
    // set root at Desktop 
    browseInfo.pidlRoot = NULL; 
    browseInfo.pszDisplayName = szDisplayName; 
    browseInfo.lpszTitle = "PATH FOR SAVE IQ DATA";  
    browseInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS; 
    browseInfo.lpfn = NULL;   
    browseInfo.lParam = 0;      

    LPITEMIDLIST lpItemIDList; 
    if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo)) 
        != NULL) 
    { 
        // GET THE PATH OF THE SELECTED FOLDER FROM THE  ITEM ID LIST. 
        if (::SHGetPathFromIDList(lpItemIDList, szBuffer)) 
        { 
            // AT THIS POINT, SZBUFFER CONTAINS THE PATH THE USER CHOSE. 
            if (szBuffer[0] == '\0') 
            { 
                // SHGETPATHFROMIDLIST FAILED, OR SHBROWSEFORFOLDER FAILED. 
                AfxMessageBox("FAIL TO GET DIRECTORY!", 
                    MB_ICONSTOP|MB_OK); 
                return ; 
            } 
            // WE HAVE A PATH IN SZBUFFER! RETURN IT. 
            strResult = szBuffer; 
        } 
        else 
        { 
            // THE THING REFERRED TO BY LPITEMIDLIST 
            // MIGHT NOT HAVE BEEN A FILE SYSTEM OBJECT. 
            // FOR WHATEVER REASON, SHGETPATHFROMIDLIST DIDN'T WORK! 
            AfxMessageBox("FAIL TO GET DIRECTORY!", 
                MB_ICONSTOP|MB_OK); 
            return ; 
        } 
        lpMalloc->Free(lpItemIDList); 
        lpMalloc->Release(); 
    } 

	m_strArchivePath = strResult;
	UpdateData(FALSE); 	
}
Example #19
0
char *FolderDlgInnerA(HWND hWnd, wchar_t *title, char *default_dir)
{
	BROWSEINFOA info;
	char display_name[MAX_PATH];
	FOLDER_DLG_INNER_DATA data;
	LPMALLOC pMalloc;
	char *ret = NULL;
	char *title_a;
	if (UniIsEmptyStr(title))
	{
		title = NULL;
	}
	if (IsEmptyStr(default_dir))
	{
		default_dir = NULL;
	}

	Zero(&data, sizeof(data));
	data.default_dir = CopyStrToUni(default_dir);

	Zero(display_name, sizeof(display_name));
	Zero(&info, sizeof(info));
	info.hwndOwner = hWnd;
	info.pidlRoot = NULL;
	info.pszDisplayName = display_name;
	title_a = CopyUniToStr(title);
	info.lpszTitle = title_a;
	info.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_SHAREABLE;
	info.lpfn = FolderDlgInnerCallbackA;
	info.lParam = (LPARAM)&data;

	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
	{
		LPITEMIDLIST pidl;

		pidl = SHBrowseForFolderA(&info);

		if (pidl)
		{
			char tmp[MAX_PATH];

			if (SHGetPathFromIDListA(pidl, tmp))
			{
				ret = CopyStr(tmp);
			}

			pMalloc->Free(pidl);
		}

		pMalloc->Release();
	}

	Free(data.default_dir);
	Free(title_a);

	return ret;
}
void CShellContextMenu::SetObjects(const QStringList &strList)
{
	// free all allocated datas
	if (m_psfFolder && bDelete)
		m_psfFolder->Release ();
	m_psfFolder = NULL;
	FreePIDLArray (m_pidlArray);
	m_pidlArray = NULL;
	
	// get IShellFolder interface of Desktop (root of shell namespace)
	IShellFolder * psfDesktop = NULL;
	SHGetDesktopFolder (&psfDesktop);	// needed to obtain full qualified pidl

	// ParseDisplayName creates a PIDL from a file system path relative to the IShellFolder interface
	// but since we use the Desktop as our interface and the Desktop is the namespace root
	// that means that it's a fully qualified PIDL, which is what we need
	LPITEMIDLIST pidl = NULL;
	
	psfDesktop->ParseDisplayName (NULL, 0, (LPOLESTR)strList[0].utf16(), NULL, &pidl, NULL);

	// now we need the parent IShellFolder interface of pidl, and the relative PIDL to that interface
	LPITEMIDLIST pidlItem = NULL;	// relative pidl
	SHBindToParentEx (pidl, IID_IShellFolder, (void **) &m_psfFolder, NULL);
	free (pidlItem);
	// get interface to IMalloc (need to free the PIDLs allocated by the shell functions)
	LPMALLOC lpMalloc = NULL;
	SHGetMalloc (&lpMalloc);
	lpMalloc->Free (pidl);

	// now we have the IShellFolder interface to the parent folder specified in the first element in strArray
	// since we assume that all objects are in the same folder (as it's stated in the MSDN)
	// we now have the IShellFolder interface to every objects parent folder
	
	IShellFolder * psfFolder = NULL;
	nItems = strList.size ();
	for (int i = 0; i < nItems; i++)
	{
                pidl=0;
		psfDesktop->ParseDisplayName (NULL, 0, (LPOLESTR)strList[i].utf16(), NULL, &pidl, NULL);
                if (pidl)
                {
                     m_pidlArray = (LPITEMIDLIST *) realloc (m_pidlArray, (i + 1) * sizeof (LPITEMIDLIST));
                     // get relative pidl via SHBindToParent
                     SHBindToParentEx (pidl, IID_IShellFolder, (void **) &psfFolder, (LPCITEMIDLIST *) &pidlItem);
                     m_pidlArray[i] = CopyPIDL (pidlItem);	// copy relative pidl to pidlArray
                     free (pidlItem);
                     lpMalloc->Free (pidl);		// free pidl allocated by ParseDisplayName
                     psfFolder->Release ();
                }
	}
	lpMalloc->Release ();
	psfDesktop->Release ();

	bDelete = TRUE;	// indicates that m_psfFolder should be deleted by CShellContextMenu
}
Example #21
0
CBrowseFolder::retVal CBrowseFolder::Show(HWND parent, CString& path, const CString& sDefaultPath /* = CString() */)
{
	retVal ret = OK;		//assume OK
	m_sDefaultPath = sDefaultPath;
	if (m_sDefaultPath.IsEmpty() && !path.IsEmpty())
	{
		// if the result path already contains a path, use that as the default path
		m_sDefaultPath = path;
	}
	LPITEMIDLIST itemIDList;

	BROWSEINFO browseInfo;

	browseInfo.hwndOwner		= parent;
	browseInfo.pidlRoot			= m_root;
	browseInfo.pszDisplayName	= m_displayName;
	browseInfo.lpszTitle		= m_title;
	browseInfo.ulFlags			= m_style;
	browseInfo.lpfn				= NULL;
	browseInfo.lParam			= (LPARAM)this;
	
	if ((_tcslen(m_CheckText) > 0)||(!m_sDefaultPath.IsEmpty()))
	{
		browseInfo.lpfn = BrowseCallBackProc;
	}
	
	itemIDList = SHBrowseForFolder(&browseInfo);

	//is the dialog canceled?
	if (!itemIDList)
		ret = CANCEL;

	if (ret != CANCEL) 
	{
		if (!SHGetPathFromIDList(itemIDList, path.GetBuffer(MAX_PATH)))		// MAX_PATH ok. Explorer can't handle paths longer than MAX_PATH.
			ret = NOPATH;

		path.ReleaseBuffer();
	
		LPMALLOC	shellMalloc;
		HRESULT		hr;

		hr = SHGetMalloc(&shellMalloc);

		if (SUCCEEDED(hr)) 
		{
			//free memory
			shellMalloc->Free(itemIDList);
			//release interface
			shellMalloc->Release();
		}
	}
	return ret;
}
Example #22
0
void WINAPI _SHFree(void *pv)
{
   if (!pv) {
      return;
   }

   LPMALLOC pMalloc = NULL;
   if (::SHGetMalloc(&pMalloc) == NOERROR) {
      pMalloc->Free(pv);
      pMalloc->Release();
   }
}
Example #23
0
/// Set File to hash in wxTextCtrl
void
AlcFrame::SetFileToHash()
{
#ifdef __WXMSW__
	wxString browseroot;
	LPITEMIDLIST pidl;
	HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl);
	if (SUCCEEDED(hr)) {
		if (!SHGetPathFromIDList(pidl, wxStringBuffer(browseroot, MAX_PATH))) {
			browseroot = wxFileName::GetHomeDir();
		}
	} else {
		browseroot = wxFileName::GetHomeDir();
	}
	if (pidl) {
		LPMALLOC pMalloc;
		SHGetMalloc(&pMalloc);
		if (pMalloc) {
			pMalloc->Free(pidl);
			pMalloc->Release();
		}
	}
#elif defined(__WXMAC__)

	FSRef fsRef;
	wxString browseroot;
	if (FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &fsRef) == noErr)
	{
		CFURLRef	urlRef		= CFURLCreateFromFSRef(NULL, &fsRef);
		CFStringRef	cfString	= CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
		CFRelease(urlRef) ;
		#if wxCHECK_VERSION(2, 9, 0)
			browseroot = wxCFStringRef(cfString).AsString(wxLocale::GetSystemEncoding());
		#else
			browseroot = wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding());
		#endif
	} else {
		browseroot = wxFileName::GetHomeDir();
	}

#else
	wxString browseroot = wxFileName::GetHomeDir();
#endif
  const wxString & filename =
    wxFileSelector (_("Select the file you want to compute the eD2k link"),
                    browseroot, wxEmptyString, wxEmptyString, wxT("*.*"),
                    wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);

  if (!filename.empty ())
    {
      m_inputFileTextCtrl->SetValue(filename);
    }
}
Example #24
0
// CoTaskMemFree uses the default OLE allocator to free a block of
// memory previously allocated through a call to CoTaskMemAlloc
void NEAR
CoTaskMemFree(LPVOID lpv)
{
	if (lpv) {
		LPMALLOC	pMalloc;
	
		if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
			pMalloc->Free(lpv);
			pMalloc->Release();
		}
	}
}
Example #25
0
// CoTaskMemRealloc changes the size of a previously allocated memory
// block in the same way that IMalloc::Realloc does
LPVOID NEAR
CoTaskMemRealloc(LPVOID lpv, ULONG cb)
{
	LPMALLOC	pMalloc;
	
	if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
		lpv = pMalloc->Realloc(lpv, cb);
		pMalloc->Release();
		return lpv;
	}

	return NULL;
}
Example #26
0
// Main routine
CString XSHBrowseForFolder(HWND hwnd,char* title,char* _path) {
  char path[MAX_PATH]; path[0]='\0';

  // Remove the last slash bar
  if (strlen(_path)>0)
  if (_path[strlen(_path)-1]=='\\')
    _path[strlen(_path)-1]='\0';

  // Get IMalloc Interface
  LPMALLOC Mymal;
  if (SHGetMalloc(&Mymal)!=NOERROR)
    return path;
  
  // Build Root directory (My Computer)
  LPITEMIDLIST Mylist;
  if (SHGetSpecialFolderLocation(hwnd,CSIDL_DRIVES,&Mylist)==NOERROR) {

    // Convert _path into browse data
    LPITEMIDLIST MyItemlist=XSHBFF_PathConvert(hwnd,_path);
    
    // Parameter structure for callback
    char Thispath[MAX_PATH]; Thispath[0]='\0';
    LPARAM CParam[2];
    CParam[0]=(LPARAM) MyItemlist;
    CParam[1]=(LPARAM) Thispath;
    // Fill the BROWSEINFO structure
    BROWSEINFO br;
    br.hwndOwner=hwnd;       // hwnd
    br.pidlRoot=NULL;        // root
    br.pszDisplayName=path;  // buffer
    br.lpszTitle=title;      // title
    br.ulFlags=BIF_RETURNONLYFSDIRS;  // dir
    br.lpfn=XSHBFF_CallbackProc;      // callback
    br.lParam=(LPARAM) CParam;          // callback params
    br.iImage=0;             // image
    // And Call SHBrowseForFolder
    LPITEMIDLIST UserList;
    if ( (UserList = SHBrowseForFolder(&br)) != NULL) {
      if (strlen(Thispath)==0) {  // No value in path
        // Convert UserList to a string
        if (SHGetPathFromIDList(UserList,path)==FALSE)
          path[0]='\0';
      } else
        strcpy(path,Thispath);
      Mymal->Free(UserList);
    }
    if (MyItemlist) Mymal->Free(MyItemlist);
    Mymal->Free(Mylist);
  }
  return path;
}
CString GetDefaultDBName()
{
	CString csDefaultPath = _T("c:\\program files\\Ditto\\");

	if(g_Opt.m_bU3)
	{
		csDefaultPath = CGetSetOptions::GetPath(PATH_DATABASE);
	}
	else
	{	
		//If portable then default to the running path
		if(CGetSetOptions::GetIsPortableDitto())
		{
			csDefaultPath.Empty();
		}
		else
		{
			LPMALLOC pMalloc;
		
			if(SUCCEEDED(::SHGetMalloc(&pMalloc))) 
			{ 
				LPITEMIDLIST pidlPrograms;
				
				SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidlPrograms);
				
				TCHAR string[MAX_PATH];
				SHGetPathFromIDList(pidlPrograms, string);
				
				pMalloc->Free(pidlPrograms);
				pMalloc->Release();
				
				csDefaultPath = string;		
			}

			FIX_CSTRING_PATH(csDefaultPath);
			csDefaultPath += "Ditto\\";
		}
	}

	CString csTempName = csDefaultPath + "Ditto.db";
	int i = 1;
	while(FileExists(csTempName))
	{
		csTempName.Format(_T("%sDitto_%d.db"), csDefaultPath, i);
		i++;
	}
	csDefaultPath = csTempName;
	
	return csDefaultPath;
}
void CPartFileConvertDlg::OnAddFolder() {
	// browse...
	
	LPMALLOC pMalloc = NULL;
	if (SHGetMalloc(&pMalloc) == NOERROR)
	{
		// buffer - a place to hold the file system pathname
		TCHAR buffer[MAX_PATH];

		// This struct holds the various options for the dialog
		BROWSEINFO bi;
		bi.hwndOwner = this->m_hWnd;
		bi.pidlRoot = NULL;
		bi.pszDisplayName = buffer;
		CString title=GetResString(IDS_IMP_SELFOLDER);
		bi.lpszTitle = title.GetBuffer(title.GetLength());
		bi.ulFlags =  BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_NONEWFOLDERBUTTON | BIF_SHAREABLE ;
		bi.lpfn = NULL;

		// Now cause the dialog to appear.
		LPITEMIDLIST pidlRoot;
		if((pidlRoot = SHBrowseForFolder(&bi)) != NULL)
		{
			bool removesrc;
			int reply=IDNO;
			
			if (thePrefs.IsExtControlsEnabled())
				reply=AfxMessageBox(GetResString(IDS_IMP_DELSRC), MB_YESNOCANCEL | MB_DEFBUTTON2 );
			
			if (reply!=IDCANCEL){
				removesrc = (reply==IDYES);

				//
				// Again, almost undocumented.  How to get a ASCII pathname
				// from the LPITEMIDLIST struct.  I guess you just have to
				// "know" this stuff.
				//
				if(SHGetPathFromIDList(pidlRoot, buffer)){
					// Do something with the converted string.
					CPartFileConvert::ScanFolderToAdd(CString(buffer), removesrc);
				}
			}

			// Free the returned item identifier list using the
			// shell's task allocator!Arghhhh.
			pMalloc->Free(pidlRoot);
		}
		pMalloc->Release();
	}
}
Example #29
0
//=================================================
// Construction 
//=================================================
CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMainDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_hSelectCursor = AfxGetApp()->LoadStandardCursor(IDC_SIZEALL);
	m_bMouseHook = FALSE;
	m_bKeyboardHook = FALSE;
	m_pThis = this;
	m_bDrawing = FALSE;
	m_bSelecting = FALSE;
	m_pDesktopDC = NULL;
	m_iBandPx = 3;
	m_bDitherLast = FALSE;
	m_hHilightWnd = NULL;
	m_bStayInTray = FALSE;
	m_bMinToTray = TRUE;
	m_iNamingOpt = 2;
	m_strImageName = _T("");
	m_hTmpDraw = NULL;

	if(!m_strImagePath.IsEmpty())
		return;

	// Get default image path use desktop for now
	LPITEMIDLIST pidl = 0;
	HRESULT hr = NOERROR;
	if(SUCCEEDED(hr = ::SHGetSpecialFolderLocation(m_hWnd, CSIDL_DESKTOP, &pidl)))
	{
		if(pidl)
		{
			::SHGetPathFromIDList(pidl, m_strImagePath.GetBuffer(MAX_PATH));
			m_strImagePath.ReleaseBuffer();

			// Clean up
			LPMALLOC pMalloc;
			hr = ::SHGetMalloc(&pMalloc);
			pMalloc->Free(pidl);
			pMalloc->Release();
		}
	}

	// Make sure we have a path
	if(m_strImagePath.GetLength() == 0)
		m_strImagePath = _T("C:\\");
	
	// Ensure trailing backslash
	if(m_strImagePath.Right(1) != _T('\\'))
		m_strImagePath += _T('\\');
}
Example #30
0
void
CPropertyPageEx::operator delete(LPVOID lpv)
{
#ifdef _WIN32
	HeapFree(GetProcessHeap(), 0, lpv);
#else
	LPMALLOC	pMalloc;

	if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pMalloc))) {
		pMalloc->Free(lpv);
		pMalloc->Release();
	}
#endif
}