本文整理汇总了C++中IShellItemArray::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellItemArray::Release方法的具体用法?C++ IShellItemArray::Release怎么用?C++ IShellItemArray::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellItemArray
的用法示例。
在下文中一共展示了IShellItemArray::Release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PyCom_BuildPyException
// @pymethod unicode|PyIExplorerCommand|GetToolTip|Description of GetToolTip.
PyObject *PyIExplorerCommand::GetToolTip(PyObject *self, PyObject *args)
{
IExplorerCommand *pIEC = GetI(self);
if ( pIEC == NULL )
return NULL;
// @pyparm <o PyIShellItemArray>|psiItemArray||Description for psiItemArray
PyObject *obpsiItemArray;
IShellItemArray * psiItemArray;
if ( !PyArg_ParseTuple(args, "O:GetToolTip", &obpsiItemArray) )
return NULL;
BOOL bPythonIsHappy = TRUE;
if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpsiItemArray, IID_IShellItemArray, (void **)&psiItemArray, TRUE /* bNoneOK */))
bPythonIsHappy = FALSE;
if (!bPythonIsHappy) return NULL;
HRESULT hr;
WCHAR *psz = 0;
PY_INTERFACE_PRECALL;
hr = pIEC->GetToolTip(psiItemArray, &psz);
if (psiItemArray) psiItemArray->Release();
PY_INTERFACE_POSTCALL;
if ( FAILED(hr) )
return PyCom_BuildPyException(hr, pIEC, IID_IExplorerCommand );
PyObject *ret = PyWinObject_FromWCHAR(psz);
CoTaskMemFree(psz);
return ret;
}
示例2: CoCreateInstance
std::vector<std::wstring> APlayerWindow::showOpenFile()
{
HRESULT hr = S_OK;
std::vector<std::wstring> filePaths;
IFileOpenDialog *fileDlg = NULL;
hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fileDlg));
if (FAILED(hr)) return filePaths;
ON_SCOPE_EXIT([&] { fileDlg->Release(); });
IKnownFolderManager *pkfm = NULL;
hr = CoCreateInstance(CLSID_KnownFolderManager,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pkfm));
if (FAILED(hr)) return filePaths;
ON_SCOPE_EXIT([&] { pkfm->Release(); });
IKnownFolder *pKnownFolder = NULL;
hr = pkfm->GetFolder(FOLDERID_PublicMusic, &pKnownFolder);
if (FAILED(hr)) return filePaths;
ON_SCOPE_EXIT([&] { pKnownFolder->Release(); });
IShellItem *psi = NULL;
hr = pKnownFolder->GetShellItem(0, IID_PPV_ARGS(&psi));
if (FAILED(hr)) return filePaths;
ON_SCOPE_EXIT([&] { psi->Release(); });
hr = fileDlg->AddPlace(psi, FDAP_BOTTOM);
COMDLG_FILTERSPEC rgSpec[] = {
{ L"ÒôÀÖÎļþ", SupportType }
};
fileDlg->SetFileTypes(1, rgSpec);
DWORD dwOptions;
fileDlg->GetOptions(&dwOptions);
fileDlg->SetOptions(dwOptions | FOS_ALLOWMULTISELECT);
hr = fileDlg->Show(NULL);
if (SUCCEEDED(hr)) {
IShellItemArray *pRets;
hr = fileDlg->GetResults(&pRets);
if (SUCCEEDED(hr)) {
DWORD count;
pRets->GetCount(&count);
for (DWORD i = 0; i < count; i++) {
IShellItem *pRet;
LPWSTR nameBuffer;
pRets->GetItemAt(i, &pRet);
pRet->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &nameBuffer);
filePaths.push_back(std::wstring(nameBuffer));
pRet->Release();
CoTaskMemFree(nameBuffer);
}
pRets->Release();
}
}
return filePaths;
}
示例3: fileOpenDialog
extern "C" LXCWIN_API HRESULT fileOpenDialog(HWND hWnd, DWORD *count, LPWSTR **result) {
*result = NULL;
HRESULT hr = S_OK;
CoInitialize(nullptr);
IFileOpenDialog *pfd = NULL;
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr)) {
// set default folder to "My Documents"
IShellItem *psiDocuments = NULL;
hr = SHCreateItemInKnownFolder(FOLDERID_Documents, 0, NULL,
IID_PPV_ARGS(&psiDocuments));
if (SUCCEEDED(hr)) {
hr = pfd->SetDefaultFolder(psiDocuments);
psiDocuments->Release();
}
// dialog title
pfd->SetTitle(L"Select files to share");
// allow multiselect, restrict to real files
DWORD dwOptions;
hr = pfd->GetOptions(&dwOptions);
if (SUCCEEDED(hr)) {
// ideally, allow selecting folders as well as files, but IFileDialog does not support this :(
pfd->SetOptions(dwOptions | FOS_ALLOWMULTISELECT | FOS_FORCEFILESYSTEM); // | FOS_PICKFOLDERS
}
// do not limit to certain file types
// show the open file dialog
hr = pfd->Show(hWnd);
if (SUCCEEDED(hr)) {
IShellItemArray *psiaResults;
hr = pfd->GetResults(&psiaResults);
if (SUCCEEDED(hr)) {
hr = psiaResults->GetCount(count);
if (SUCCEEDED(hr)) {
*result = (LPWSTR*)calloc(*count, sizeof(LPWSTR));
if (*result != NULL) {
for (DWORD i = 0; i < *count; i++) {
IShellItem *resultItem = NULL;
hr = psiaResults->GetItemAt(i, &resultItem);
if (SUCCEEDED(hr)) {
resultItem->GetDisplayName(SIGDN_FILESYSPATH, &((*result)[i]));
resultItem->Release();
}
}
// paths now contains selected files
}
}
psiaResults->Release();
}
}
pfd->Release();
}
return hr;
}
示例4: v_ExecuteLibCommand
HRESULT v_ExecuteLibCommand()
{
// Get the private and public save locations.
IShellItem *psiPrivateSaveLoc;
HRESULT hr = _plib->GetDefaultSaveFolder(DSFT_PRIVATE, IID_PPV_ARGS(&psiPrivateSaveLoc));
if (SUCCEEDED(hr))
{
IShellItem *psiPublicSaveLoc;
hr = _plib->GetDefaultSaveFolder(DSFT_PUBLIC, IID_PPV_ARGS(&psiPublicSaveLoc));
if (SUCCEEDED(hr))
{
// Get the list of folders that match the specified filter.
IShellItemArray *psiaFolders;
hr = _plib->GetFolders(_lffFilter, IID_PPV_ARGS(&psiaFolders));
if (SUCCEEDED(hr))
{
DWORD cFolders;
hr = psiaFolders->GetCount(&cFolders);
if (SUCCEEDED(hr))
{
Output(L"Library contains %u folders:\n", cFolders);
for (DWORD iFolder = 0; iFolder < cFolders; iFolder++)
{
IShellItem *psiFolder;
if (SUCCEEDED(psiaFolders->GetItemAt(iFolder, &psiFolder)))
{
// Print each folder's name as an absolute path, suitable for parsing in the Shell Namespace (e.g SHParseDisplayName).
// For file system folders (the typical case), this will be the file system path of the folder.
PWSTR pszDisplay;
if (SUCCEEDED(psiFolder->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &pszDisplay)))
{
PCWSTR pszPrefix = L" ";
int iCompare;
if (S_OK == psiPrivateSaveLoc->Compare(psiFolder, SICHINT_CANONICAL | SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL, &iCompare))
{
pszPrefix = L"* ";
}
else if (S_OK == psiPublicSaveLoc->Compare(psiFolder, SICHINT_CANONICAL | SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL, &iCompare))
{
pszPrefix = L"# ";
}
Output(L"%s%s\n", pszPrefix, pszDisplay);
CoTaskMemFree(pszDisplay);
}
psiFolder->Release();
}
}
}
psiaFolders->Release();
}
psiPublicSaveLoc->Release();
}
psiPrivateSaveLoc->Release();
}
return hr;
}
示例5: OnFileOk
STDMETHODIMP COpenFileListener::OnFileOk(IFileDialog* pfd)
{
IShellItemArray *psiaResults;
IFileDialogCustomize *pfdc;
HRESULT hr;
IFileOpenDialog *fod;
FILEINFO fileinfoTmp = {0};
DWORD choice;
fileinfoTmp.parentList = pFInfoList;
hr = pfd->QueryInterface(IID_PPV_ARGS(&fod));
if(SUCCEEDED(hr)) {
hr = fod->GetSelectedItems(&psiaResults);
if (SUCCEEDED(hr)) {
DWORD fileCount;
IShellItem *isi;
LPWSTR pwsz = NULL;
psiaResults->GetCount(&fileCount);
for(DWORD i=0;i<fileCount;i++) {
psiaResults->GetItemAt(i,&isi);
isi->GetDisplayName(SIGDN_FILESYSPATH,&pwsz);
isi->Release();
fileinfoTmp.szFilename = pwsz;
pFInfoList->fInfos.push_back(fileinfoTmp);
CoTaskMemFree(pwsz);
}
psiaResults->Release();
}
fod->Release();
}
hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdc));
if(SUCCEEDED(hr)) {
hr = pfdc->GetSelectedControlItem(FDIALOG_OPENCHOICES,&choice);
if(SUCCEEDED(hr)) {
if(choice==FDIALOG_CHOICE_REPARENT) {
pFInfoList->uiCmdOpts = CMD_REPARENT;
}
else if(choice==FDIALOG_CHOICE_ALLHASHES) {
pFInfoList->uiCmdOpts = CMD_ALLHASHES;
}
else if(choice==FDIALOG_CHOICE_BSD) {
pFInfoList->uiCmdOpts = CMD_FORCE_BSD;
}
}
pfdc->Release();
}
return S_OK;
}
示例6: ReportSelectedItemsFromSite
void ReportSelectedItemsFromSite(IUnknown *punkSite)
{
IShellItemArray *psia;
HRESULT hr = GetSelectionFromSite(punkSite, TRUE, &psia);
if (SUCCEEDED(hr))
{
ReportSelectedItems(punkSite, psia);
psia->Release();
}
}
示例7: wmain
int wmain()
{
// File dialog drag and drop feature requires OLE
HRESULT hr = OleInitialize(NULL);
if (SUCCEEDED(hr))
{
ISearchFolderItemFactory *pSearchFolderItemFactory;
hr = CoCreateInstance(CLSID_SearchFolderItemFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pSearchFolderItemFactory));
if (SUCCEEDED(hr))
{
IShellItemArray *psiaScope;
hr = CreateScope(&psiaScope);
if (SUCCEEDED(hr))
{
hr = pSearchFolderItemFactory->SetScope(psiaScope);
if (SUCCEEDED(hr))
{
// Sets the display name of the search
hr = pSearchFolderItemFactory->SetDisplayName(L"Sample Query");
if (SUCCEEDED(hr))
{
ICondition* pCondition;
hr = GetCondition(&pCondition);
if (SUCCEEDED(hr))
{
// Sets the condition for pSearchFolderItemFactory
hr = pSearchFolderItemFactory->SetCondition(pCondition);
if (SUCCEEDED(hr))
{
// This retrieves an IShellItem of the search. It is a virtual child of the desktop.
IShellItem* pShellItemSearch;
hr = pSearchFolderItemFactory->GetShellItem(IID_PPV_ARGS(&pShellItemSearch));
if (SUCCEEDED(hr))
{
OpenCommonFileDialogTo(pShellItemSearch);
pShellItemSearch->Release();
}
}
pCondition->Release();
}
}
}
psiaScope->Release();
}
pSearchFolderItemFactory->Release();
}
OleUninitialize();
}
return 0;
}
示例8: ReportSelectedItemsFromSite
void ReportSelectedItemsFromSite(IUnknown *punkSite)
{
if (selected_string) {
delete[] selected_string;
selected_string = NULL;
}
IShellItemArray *psia;
HRESULT hr = GetSelectionFromSite(punkSite, TRUE, &psia);
if (SUCCEEDED(hr)) {
ReportSelectedItems(punkSite, psia);
psia->Release();
}
}
示例9: GetShellItem
// Populates item. It is the responsibility of the caller to call item->Release()
// if the return value indicates success
HRESULT ComposerShellMenu::GetShellItem(IShellItem ** item, PBOOLEAN isFile)
{
HRESULT hr = E_FAIL;
*item = NULL;
if (m_Folder)
{
hr = SHCreateItemFromIDList(m_Folder, IID_PPV_ARGS(item));
}
else if (m_Data)
{
IShellItemArray *itemArray = NULL;
hr = SHCreateShellItemArrayFromDataObject(m_Data, IID_PPV_ARGS(&itemArray));
if (SUCCEEDED(hr))
{
DWORD count = 0;
hr = itemArray->GetCount(&count);
if (SUCCEEDED(hr))
{
if (1 == count)
{
hr = itemArray->GetItemAt(0, item);
}
else
{
hr = E_FAIL;
}
}
itemArray->Release();
itemArray = NULL;
}
}
if (SUCCEEDED(hr))
{
hr = IsShellItemValid(*item, false, isFile);
if (FAILED(hr))
{
(*item)->Release();
*item = NULL;
}
}
return hr;
}
示例10: p
std::vector<fs::path> open_file_dialog::get_paths()
{
IShellItemArray *items = NULL;
dlg_->GetResults(&items);
if (items == NULL)
{
return std::vector<fs::path>();
}
DWORD count;
items->GetCount(&count);
std::vector<fs::path> paths;
for (DWORD i = 0; i < count; i++)
{
IShellItem* item = NULL;
items->GetItemAt(i, &item);
PWSTR path = NULL;
HRESULT res = item->GetDisplayName(SIGDN_FILESYSPATH, &path);
if (res != S_OK)
{
LOG(warning) << "Could not get display name from path: " << std::hex << res;
continue;
}
fs::path p(path);
paths.push_back(p);
CoTaskMemFree(path);
item->Release();
}
items->Release();
return paths;
}
示例11: GetSelectedItems
BOOL GetSelectedItems(IFileDialog *fd, vector<Wstr> *res)
{
IFolderView2 *fv = NULL;
if (FAILED(IUnknown_QueryService(fd, SID_SFolderView, IID_PPV_ARGS(&fv)))) return FALSE;
scope_defer([&](){ fv->Release(); });
IShellItemArray *sia = NULL;
if (FAILED(fv->GetSelection(TRUE, &sia))) return FALSE;
scope_defer([&](){ sia->Release(); });
DWORD num = 0;
if (FAILED(sia->GetCount(&num))) return FALSE;
for (DWORD i=0; i < num; i++) {
IShellItem *si = NULL;
if (FAILED(sia->GetItemAt(i, &si))) return FALSE;
scope_defer([&](){ si->Release(); });
// LPITEMIDLIST idl;
// DWORD val = 0;
// if (SUCCEEDED(::SHGetIDListFromObject(si, &idl))) {
// PITEMID_CHILD ic = ILFindLastID(idl);
// HRESULT hr = fv->GetSelectionState(ic, &val);
// DBG("hr=%x val=%x\n", hr, val);
// }
PWSTR path = NULL;
if (FAILED(si->GetDisplayName(SIGDN_FILESYSPATH, &path))) continue;
scope_defer([&](){ ::CoTaskMemFree(path); });
res->push_back(path);
DBGW(L"path=%s\n", path);
}
return TRUE;
}
示例12: deleteItems
bool OsShell::deleteItems(const std::vector<std::wstring>& items, bool moveToTrash, void * parentWindow)
{
ComInitializer comInitializer;
assert_r(parentWindow);
std::vector<ITEMIDLIST*> idLists;
for (auto& path: items)
{
__unaligned ITEMIDLIST* idl = ILCreateFromPathW(path.c_str());
if (!idl)
{
for (auto& pid : idLists)
ILFree(pid);
qInfo() << "ILCreateFromPathW" << "failed for path" << QString::fromWCharArray(path.c_str());
return false;
}
idLists.push_back(idl);
assert_r(idLists.back());
}
IShellItemArray * iArray = 0;
HRESULT result = SHCreateShellItemArrayFromIDLists((UINT)idLists.size(), (LPCITEMIDLIST*)idLists.data(), &iArray);
// Freeing memory
for (auto& pid: idLists)
ILFree(pid);
idLists.clear();
if (!SUCCEEDED(result) || !iArray)
{
qInfo() << "SHCreateShellItemArrayFromIDLists failed";
return false;
}
IFileOperation * iOperation = 0;
result = CoCreateInstance(CLSID_FileOperation, 0, CLSCTX_ALL, IID_IFileOperation, (void**)&iOperation);
if (!SUCCEEDED(result) || !iOperation)
{
qInfo() << "CoCreateInstance(CLSID_FileOperation, 0, CLSCTX_ALL, IID_IFileOperation, (void**)&iOperation) failed";
return false;
}
result = iOperation->DeleteItems(iArray);
if (!SUCCEEDED(result))
{
qInfo() << "DeleteItems failed";
}
else
{
if (moveToTrash)
{
result = iOperation->SetOperationFlags(FOF_ALLOWUNDO);
}
else
result = iOperation->SetOperationFlags(FOF_WANTNUKEWARNING);
if (!SUCCEEDED(result))
qInfo() << "SetOperationFlags failed";
result = iOperation->SetOwnerWindow((HWND) parentWindow);
if (!SUCCEEDED(result))
qInfo() << "SetOwnerWindow failed";
result = iOperation->PerformOperations();
if (!SUCCEEDED(result) && result != COPYENGINE_E_USER_CANCELLED)
{
qInfo() << "PerformOperations failed";
if (result == COPYENGINE_E_REQUIRES_ELEVATION)
qInfo() << "Elevation required";
}
else
result = S_OK;
}
iOperation->Release();
iArray->Release();
return SUCCEEDED(result);
}
示例13: NFD_OpenDialogMultiple
nfdresult_t NFD_OpenDialogMultiple( const nfdchar_t *filterList,
const nfdchar_t *defaultPath,
nfdpathset_t *outPaths )
{
nfdresult_t nfdResult = NFD_ERROR;
// Init COM library.
HRESULT result = ::CoInitializeEx(NULL,
::COINIT_APARTMENTTHREADED |
::COINIT_DISABLE_OLE1DDE );
if ( !SUCCEEDED(result))
{
NFDi_SetError("Could not initialize COM.");
return NFD_ERROR;
}
::IFileOpenDialog *fileOpenDialog(NULL);
// Create dialog
result = ::CoCreateInstance(::CLSID_FileOpenDialog, NULL,
CLSCTX_ALL, ::IID_IFileOpenDialog,
reinterpret_cast<void**>(&fileOpenDialog) );
if ( !SUCCEEDED(result) )
{
NFDi_SetError("Could not create dialog.");
goto end;
}
// Build the filter list
if ( !AddFiltersToDialog( fileOpenDialog, filterList ) )
{
goto end;
}
// Set the default path
if ( !SetDefaultPath( fileOpenDialog, defaultPath ) )
{
goto end;
}
// Set a flag for multiple options
DWORD dwFlags;
result = fileOpenDialog->GetOptions(&dwFlags);
if ( !SUCCEEDED(result) )
{
NFDi_SetError("Could not get options.");
goto end;
}
result = fileOpenDialog->SetOptions(dwFlags | FOS_ALLOWMULTISELECT);
if ( !SUCCEEDED(result) )
{
NFDi_SetError("Could not set options.");
goto end;
}
// Show the dialog.
result = fileOpenDialog->Show(NULL);
if ( SUCCEEDED(result) )
{
IShellItemArray *shellItems;
result = fileOpenDialog->GetResults( &shellItems );
if ( !SUCCEEDED(result) )
{
NFDi_SetError("Could not get shell items.");
goto end;
}
if ( AllocPathSet( shellItems, outPaths ) == NFD_ERROR )
{
goto end;
}
shellItems->Release();
nfdResult = NFD_OKAY;
}
else if (result == HRESULT_FROM_WIN32(ERROR_CANCELLED) )
{
nfdResult = NFD_CANCEL;
}
else
{
NFDi_SetError("File dialog box show failed.");
nfdResult = NFD_ERROR;
}
end:
::CoUninitialize();
return nfdResult;
}
示例14: runModalInternal
//-----------------------------------------------------------------------------
bool VistaFileSelector::runModalInternal ()
{
fileDialog = 0;
HRESULT hr = -1;
if (style == kSelectSaveFile)
{
hr = CoCreateInstance (CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IFileDialog, &fileDialog));
if (defaultSaveName)
{
fileDialog->SetFileName (UTF8StringHelper (defaultSaveName));
}
}
else
{
hr = CoCreateInstance (CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IFileDialog, &fileDialog));
if (SUCCEEDED (hr))
{
if (style == kSelectDirectory)
{
DWORD dwOptions = 0;
hr = fileDialog->GetOptions (&dwOptions);
if (SUCCEEDED (hr))
hr = fileDialog->SetOptions (dwOptions | FOS_PICKFOLDERS);
if (FAILED (hr))
{
fileDialog->Release ();
fileDialog = 0;
return false;
}
}
if (allowMultiFileSelection)
{
DWORD dwOptions = 0;
hr = fileDialog->GetOptions (&dwOptions);
if (SUCCEEDED (hr))
hr = fileDialog->SetOptions (dwOptions | FOS_ALLOWMULTISELECT);
if (FAILED (hr))
{
fileDialog->Release ();
fileDialog = 0;
return false;
}
}
}
}
if (FAILED (hr))
{
fileDialog = 0;
return false;
}
if (title)
hr = fileDialog->SetTitle (UTF8StringHelper (title));
DWORD numExtensions = 0;
DWORD defaultFileTypeIndex = 0;
COMDLG_FILTERSPEC* filters = buildExtensionFilter (extensions, defaultExtension, numExtensions, defaultFileTypeIndex);
if (filters)
{
fileDialog->SetFileTypes (numExtensions, filters);
if (defaultFileTypeIndex)
fileDialog->SetFileTypeIndex (defaultFileTypeIndex);
}
if (initialPath && _SHCreateItemFromParsingName)
{
IShellItem* shellItem;
hr = _SHCreateItemFromParsingName (UTF8StringHelper (initialPath), 0, IID_PPV_ARG (IShellItem, &shellItem));
if (SUCCEEDED (hr))
{
fileDialog->SetFolder (shellItem);
shellItem->Release ();
}
}
Win32Frame* win32Frame = frame->getPlatformFrame () ? dynamic_cast<Win32Frame*> (frame->getPlatformFrame ()) : 0;
hr = fileDialog->Show (win32Frame ? win32Frame->getPlatformWindow () : 0);
if (SUCCEEDED (hr))
{
if (allowMultiFileSelection)
{
IFileOpenDialog* openFileDialog = 0;
hr = fileDialog->QueryInterface (IID_PPV_ARG(IFileOpenDialog, &openFileDialog));
if (SUCCEEDED (hr))
{
IShellItemArray* items;
hr = openFileDialog->GetResults (&items);
if (SUCCEEDED (hr))
{
DWORD count;
hr = items->GetCount (&count);
for (DWORD i = 0; i < count; i++)
{
IShellItem* item;
hr = items->GetItemAt (i, &item);
if (SUCCEEDED (hr))
{
LPWSTR filesysPath = 0;
hr = item->GetDisplayName (SIGDN_FILESYSPATH, &filesysPath);
if (SUCCEEDED (hr))
{
//.........这里部分代码省略.........
示例15: showDirDialog
QStringList showDirDialog(IFileOpenDialog* pDialog, QWidget* parent)
{
Q_ASSERT(pDialog != NULL);
QStringList Result;
if (parent == NULL)
parent = QApplication::activeWindow();
HWND hwndParent = parent ? parent->window()->winId() : NULL;
HRESULT HResult = pDialog->Show(hwndParent);
if (SUCCEEDED(HResult))
{
// Что-то было выбрано.
IShellItemArray* pShellItemArray;
HResult = pDialog->GetResults(&pShellItemArray);
if (SUCCEEDED(HResult))
{
DWORD ItemsCount;
HResult = pShellItemArray->GetCount(&ItemsCount);
if (SUCCEEDED(HResult))
{
IShellItem* pItem;
for (DWORD i = 0; i < ItemsCount; ++i)
{
HResult = pShellItemArray->GetItemAt(i, &pItem);
if (SUCCEEDED(HResult))
{
wchar_t* lpwName;
HResult = pItem->GetDisplayName(SIGDN_FILESYSPATH, &lpwName);
if (SUCCEEDED(HResult))
{
Result.append(QString::fromWCharArray(lpwName));
CoTaskMemFree(lpwName);
}
else {
qWarning("IShellItem::GetDisplayName error: %s.",
qPrintable(GetSystemErrorString(HResult)));
}
pItem->Release();
}
else {
qWarning("IShellItemArray::GetItemAt(%lu, ...) error: %s.",
i, qPrintable(GetSystemErrorString(HResult)));
}
}
pShellItemArray->Release();
}
else {
qWarning("IShellItemArray::GetCount error: %s",
qPrintable(GetSystemErrorString(HResult)));
}
}
else {
qWarning("IFileOpenDialog::GetResults error: %s",
qPrintable(GetSystemErrorString(HResult)));
}
}
else {
if (HResult == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
// Пользователь ничего не выбрал.
}
else {
qWarning("IFileOpenDialog::Show error: %s",
qPrintable(GetSystemErrorString(HResult)));
}
}
return Result;
}