IFileIsInUse* CreateIFileIsInUse(const string& File) { IFileIsInUse *pfiu = nullptr; IRunningObjectTable *prot; if (SUCCEEDED(GetRunningObjectTable(0, &prot))) { IMoniker *pmkFile; if (SUCCEEDED(CreateFileMoniker(File.data(), &pmkFile))) { IEnumMoniker *penumMk; if (SUCCEEDED(prot->EnumRunning(&penumMk))) { HRESULT hr = E_FAIL; ULONG celt; IMoniker *pmk; while (FAILED(hr) && (penumMk->Next(1, &pmk, &celt) == S_OK)) { DWORD dwType; if (SUCCEEDED(pmk->IsSystemMoniker(&dwType)) && dwType == MKSYS_FILEMONIKER) { IMoniker *pmkPrefix; if (SUCCEEDED(pmkFile->CommonPrefixWith(pmk, &pmkPrefix))) { if (pmkFile->IsEqual(pmkPrefix) == S_OK) { IUnknown *punk; if (prot->GetObject(pmk, &punk) == S_OK) { hr = punk->QueryInterface( #ifdef __GNUC__ IID_IFileIsInUse, IID_PPV_ARGS_Helper(&pfiu) #else IID_PPV_ARGS(&pfiu) #endif ); punk->Release(); } } pmkPrefix->Release(); } } pmk->Release(); } penumMk->Release(); } pmkFile->Release(); } prot->Release(); } return pfiu; }
// @pymethod int|PyIMoniker|IsEqual|Compares this moniker with a specified moniker and indicates whether they are identical. PyObject *PyIMoniker::IsEqual(PyObject *self, PyObject *args) { PyObject *obOther; // @pyparm <o PyIMoniker>|other||The moniker to compare if (!PyArg_ParseTuple(args, "O:IsEqual", &obOther)) return NULL; IMoniker *pMy = GetI(self); if (pMy==NULL) return NULL; IMoniker *pOther; if (!PyCom_InterfaceFromPyInstanceOrObject(obOther, IID_IMoniker, (void **)&pOther, FALSE)) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pMy->IsEqual(pOther); pOther->Release(); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr, pMy, IID_IMoniker); return PyInt_FromLong(hr); }