本文整理汇总了C++中IFileOperation::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ IFileOperation::Release方法的具体用法?C++ IFileOperation::Release怎么用?C++ IFileOperation::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileOperation
的用法示例。
在下文中一共展示了IFileOperation::Release方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exec
bool MoveToTrash::exec() const
{
HRESULT result = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (!SUCCEEDED(result))
return false;
IFileOperation *fo = nullptr;
result = CoCreateInstance(CLSID_FileOperation, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&fo));
if (!SUCCEEDED(result)) {
CoUninitialize();
return false;
}
ulong flags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
// if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8)
// flags |= FOFX_RECYCLEONDELETE;
result = fo->SetOperationFlags(flags);
if (SUCCEEDED(result)) {
IShellItem *iShellItem = nullptr;
result = SHCreateItemFromParsingName(path.toStdWString().c_str(), nullptr, IID_PPV_ARGS(&iShellItem));
if (SUCCEEDED(result)) {
result = fo->DeleteItem(iShellItem, nullptr);
iShellItem->Release();
}
if (SUCCEEDED(result))
result = fo->PerformOperations();
}
fo->Release();
CoUninitialize();
return SUCCEEDED(result);
}
示例2: 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);
}
示例3: RemoteCodeFunc
//.........这里部分代码省略.........
{
// Load the non-Kernel32.dll functions that we need.
W7EUtils::GetProcAddr< HRESULT (STDAPICALLTYPE *)(LPVOID pvReserved) >
tfpCoInitialize( pArgs->fpGetProcAddress, hModuleOle32, pArgs->szCoInitialize );
W7EUtils::GetProcAddr< void (STDAPICALLTYPE *)(void) >
tfpCoUninitialize( pArgs->fpGetProcAddress, hModuleOle32, pArgs->szCoUninitialize );
W7EUtils::GetProcAddr< HRESULT (STDAPICALLTYPE *)(LPCWSTR pszName, BIND_OPTS *pBindOptions, REFIID riid, void **ppv) >
tfpCoGetObject( pArgs->fpGetProcAddress, hModuleOle32, pArgs->szCoGetObject );
W7EUtils::GetProcAddr< HRESULT (STDAPICALLTYPE *)(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, void ** ppv) >
tfpCoCreateInstance( pArgs->fpGetProcAddress, hModuleOle32, pArgs->szCoCreateInstance );
W7EUtils::GetProcAddr< HRESULT (STDAPICALLTYPE *)(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv) >
tfpSHCreateItemFromParsingName( pArgs->fpGetProcAddress, hModuleShell32, pArgs->szSHCreateItemFPN );
W7EUtils::GetProcAddr< BOOL (STDAPICALLTYPE *)(LPSHELLEXECUTEINFOW lpExecInfo) >
tfpShellExecuteEx( pArgs->fpGetProcAddress, hModuleShell32, pArgs->szShellExecuteExW );
if (0 != tfpCoInitialize.f
&& 0 != tfpCoUninitialize.f
&& 0 != tfpCoGetObject.f
&& 0 != tfpCoCreateInstance.f
&& 0 != tfpSHCreateItemFromParsingName.f
&& 0 != tfpShellExecuteEx.f)
{
if (S_OK == tfpCoInitialize.f(NULL))
{
BIND_OPTS3 bo;
for(int i = 0; i < sizeof(bo); ++i) { reinterpret_cast< BYTE * >(&bo)[i] = 0; } // This loop is easier than pushing ZeroMemory or memset through pArgs.
bo.cbStruct = sizeof(bo);
bo.dwClassContext = CLSCTX_LOCAL_SERVER;
// For testing other COM objects/methods, start here.
{
IFileOperation *pFileOp = 0;
IShellItem *pSHISource = 0;
IShellItem *pSHIDestination = 0;
IShellItem *pSHIDelete = 0;
// This is a completely standard call to IFileOperation, if you ignore all the pArgs/func-pointer indirection.
if (
(pArgs->szEIFOMoniker && S_OK == tfpCoGetObject.f( pArgs->szEIFOMoniker, &bo, *pArgs->pIID_EIFO, reinterpret_cast< void ** >(&pFileOp)))
|| (pArgs->pIID_EIFOClass && S_OK == tfpCoCreateInstance.f( *pArgs->pIID_EIFOClass, NULL, CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, *pArgs->pIID_EIFO, reinterpret_cast< void ** >(&pFileOp)))
)
if (0 != pFileOp)
if (S_OK == pFileOp->SetOperationFlags(FOF_NOCONFIRMATION|FOF_SILENT|FOFX_SHOWELEVATIONPROMPT|FOFX_NOCOPYHOOKS|FOFX_REQUIREELEVATION))
if (S_OK == tfpSHCreateItemFromParsingName.f( pArgs->szSourceDll, NULL, *pArgs->pIID_ShellItem2, reinterpret_cast< void ** >(&pSHISource)))
if (0 != pSHISource)
if (S_OK == tfpSHCreateItemFromParsingName.f( pArgs->szElevDir, NULL, *pArgs->pIID_ShellItem2, reinterpret_cast< void ** >(&pSHIDestination)))
if (0 != pSHIDestination)
if (S_OK == pFileOp->CopyItem(pSHISource, pSHIDestination, pArgs->szElevDll, NULL))
if (S_OK == pFileOp->PerformOperations())
{
// Use ShellExecuteEx to launch the "part 2" target process. Again, a completely standard API call.
// (Note: Don't use CreateProcess as it seems not to do the auto-elevation stuff.)
SHELLEXECUTEINFO shinfo;
for(int i = 0; i < sizeof(shinfo); ++i) { reinterpret_cast< BYTE * >(&shinfo)[i] = 0; } // This loop is easier than pushing ZeroMemory or memset through pArgs.
shinfo.cbSize = sizeof(shinfo);
shinfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shinfo.lpFile = pArgs->szElevExeFull;
shinfo.lpParameters = pArgs->szElevArgs;
shinfo.lpDirectory = pArgs->szElevDir;
shinfo.nShow = SW_SHOW;
if (tfpShellExecuteEx.f(&shinfo) && shinfo.hProcess != NULL)
{
// Wait for the "part 2" target process to finish.
pArgs->fpWaitForSingleObject(shinfo.hProcess, INFINITE);
pArgs->fpCloseHandle(shinfo.hProcess);
}
// Another standard call to IFileOperation, this time to delete our dummy DLL. We clean up our mess.
if (S_OK == tfpSHCreateItemFromParsingName.f( pArgs->szElevDllFull, NULL, *pArgs->pIID_ShellItem2, reinterpret_cast< void ** >(&pSHIDelete)))
if (0 != pSHIDelete)
if (S_OK == pFileOp->DeleteItem(pSHIDelete, NULL))
{
pFileOp->PerformOperations();
}
}
if (pSHIDelete) { pSHIDelete->Release(); }
if (pSHIDestination) { pSHIDestination->Release(); }
if (pSHISource) { pSHISource->Release(); }
if (pFileOp) { pFileOp->Release(); }
}
tfpCoUninitialize.f();
}
}
}
if (hModuleShell32) { pArgs->fpFreeLibrary(hModuleShell32); }
if (hModuleOle32) { pArgs->fpFreeLibrary(hModuleOle32); }
return 0;
}