// @pymethod |PyICategoryProvider|CreateCategory|Description of CreateCategory. PyObject *PyICategoryProvider::CreateCategory(PyObject *self, PyObject *args) { ICategoryProvider *pICP = GetI(self); if ( pICP == NULL ) return NULL; GUID guid; PyObject *obpguid; // @pyparm <o PyIID>|guid||Description for pguid IID riid; PyObject *obriid; // @pyparm <o PyIID>|riid||Description for riid if ( !PyArg_ParseTuple(args, "OO:CreateCategory", &obpguid, &obriid) ) return NULL; if (!PyWinObject_AsIID(obpguid, &guid ) || !PyWinObject_AsIID(obriid, &riid)) return NULL; HRESULT hr; void *ret; PY_INTERFACE_PRECALL; hr = pICP->CreateCategory( &guid, riid, &ret ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pICP, IID_ICategoryProvider ); return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid, FALSE); }
// @pymethod |PyIShellItemArray|BindToHandler|Description of BindToHandler. PyObject *PyIShellItemArray::BindToHandler(PyObject *self, PyObject *args) { IShellItemArray *pISIA = GetI(self); if ( pISIA == NULL ) return NULL; // @pyparm <o PyIBindCtx>|pbc||Description for pbc // @pyparm <o PyIID>|rbhid||Description for rbhid // @pyparm <o PyIID>|riid||Description for riid PyObject *obpbc; PyObject *obrbhid; PyObject *obriid; IBindCtx *pbc; IID rbhid; IID riid; void *pvOut; if ( !PyArg_ParseTuple(args, "OOO:BindToHandler", &obpbc, &obrbhid, &obriid) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpbc, IID_IBindCtx, (void **)&pbc, TRUE /* bNoneOK */)) bPythonIsHappy = FALSE; if (!PyWinObject_AsIID(obrbhid, &rbhid)) bPythonIsHappy = FALSE; if (!PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISIA->BindToHandler( pbc, rbhid, riid, &pvOut ); if (pbc) pbc->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISIA, IID_IShellItemArray ); return PyCom_PyObjectFromIUnknown((IUnknown *)pvOut, riid, FALSE); }
// @pymethod interface|PyIShellItem|BindToHandler|Creates an instance of one of the item's handlers PyObject *PyIShellItem::BindToHandler(PyObject *self, PyObject *args) { IShellItem *pISI = GetI(self); if ( pISI == NULL ) return NULL; // @pyparm <o PyIBindCtx>|pbc||Used to pass parameters that influence the binding operation, can be None // @pyparm <o PyIID>|bhid||GUID that identifies a handler (shell.BHID_*) // @pyparm <o PyIID>|riid||The interface to return PyObject *obpbc; PyObject *obbhid; PyObject *obriid; IBindCtx *pbc; IID bhid; IID riid; void *pv; if ( !PyArg_ParseTuple(args, "OOO:BindToHandler", &obpbc, &obbhid, &obriid) ) return NULL; if (!PyWinObject_AsIID(obbhid, &bhid)) return NULL; if (!PyWinObject_AsIID(obriid, &riid)) return NULL; if (!PyCom_InterfaceFromPyInstanceOrObject(obpbc, IID_IBindCtx, (void **)&pbc, TRUE /* bNoneOK */)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISI->BindToHandler( pbc, bhid, riid, &pv ); if (pbc) pbc->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISI, IID_IShellItem ); return PyCom_PyObjectFromIUnknown((IUnknown *)pv, riid, FALSE); }
// @pymethod <o PyRecord>|pythoncom|GetRecordFromGuids|Creates a new record object from the given GUIDs PyObject *pythoncom_GetRecordFromGuids(PyObject *self, PyObject *args) { void *data = NULL; PyObject *obGuid, *obInfoGuid, *obdata=Py_None; int major, minor, lcid; int cb = 0; if (!PyArg_ParseTuple(args, "OiiiO|O:GetRecordFromGuids", &obGuid, // @pyparm <o PyIID>|iid||The GUID of the type library &major, // @pyparm int|verMajor||The major version number of the type lib. &minor, // @pyparm int|verMinor||The minor version number of the type lib. &lcid, // @pyparm int|lcid||The LCID of the type lib. &obInfoGuid, // @pyparm <o PyIID>|infoIID||The GUID of the record info in the library &obdata)) // @pyparm string or buffer|data|None|The raw data to initialize the record with. return NULL; if (!PyWinObject_AsReadBuffer(obdata, &data, &cb, TRUE)) return NULL; GUID guid, infoGuid; if (!PyWinObject_AsIID(obGuid, &guid)) return NULL; if (!PyWinObject_AsIID(obInfoGuid, &infoGuid)) return NULL; IRecordInfo *i = NULL; HRESULT hr = GetRecordInfoFromGuids(guid, major, minor, lcid, infoGuid, &i); if (FAILED(hr)) return PyCom_BuildPyException(hr); PyObject *ret = PyObject_FromRecordInfo(i, data, cb); i->Release(); return ret; }
// @pymethod |PyIBackgroundCopyManager|GetJob|Description of GetJob. PyObject *PyIBackgroundCopyManager::GetJob(PyObject *self, PyObject *args) { IBackgroundCopyManager *pIBCM = GetI(self); if ( pIBCM == NULL ) return NULL; // @pyparm <o PyIID>|jobID||Description for jobID PyObject *objobID; IID jobID; IBackgroundCopyJob *ppJob; if ( !PyArg_ParseTuple(args, "O:GetJob", &objobID) ) return NULL; BOOL bPythonIsHappy = TRUE; if (!PyWinObject_AsIID(objobID, &jobID)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIBCM->GetJob( jobID, &ppJob ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIBCM, IID_IBackgroundCopyManager ); PyObject *obppJob; obppJob = PyCom_PyObjectFromIUnknown(ppJob, IID_IBackgroundCopyJob, FALSE); PyObject *pyretval = Py_BuildValue("O", obppJob); Py_XDECREF(obppJob); return pyretval; }
// @pymethod |PyIShellItemArray|GetPropertyDescriptionList|Description of GetPropertyDescriptionList. PyObject *PyIShellItemArray::GetPropertyDescriptionList(PyObject *self, PyObject *args) { IShellItemArray *pISIA = GetI(self); if ( pISIA == NULL ) return NULL; PROPERTYKEY keyType; PyObject *obkeyType; // @pyparm <o PyREFPROPERTYKEY>|keyType||Description for keyType // @pyparm <o PyIID>|riid||Description for riid PyObject *obriid; IID riid; void *pv; if ( !PyArg_ParseTuple(args, "OO:GetPropertyDescriptionList", &obkeyType, &obriid) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyObject_AsSHCOLUMNID(obkeyType, &keyType)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISIA->GetPropertyDescriptionList( keyType, riid, &pv ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISIA, IID_IShellItemArray ); return PyCom_PyObjectFromIUnknown((IUnknown *)pv, riid, FALSE); }
// @pymethod |PyICatRegister|UnRegisterClassReqCategories|Unregisters the class as requiring one or more component categories. PyObject *PyICatRegister::UnRegisterClassReqCategories(PyObject *self, PyObject *args) { PyObject *obCLSID, *obCatIds; if ( !PyArg_ParseTuple(args, "OO:UnRegisterClassReqCategories", &obCLSID, // @pyparm <o PyIID>|clsid||Class ID of the relevent class &obCatIds) ) // @pyparm [<o PyIID>, ...]|[catId, ...]||A sequence of category IDs to be unregistered for the class. return NULL; ICatRegister *pICR = GetI(self); if ( pICR == NULL ) return NULL; CLSID clsid; if (!PyWinObject_AsIID(obCLSID, &clsid)) { PyErr_SetString(PyExc_TypeError, "CLSID is not valid"); return NULL; } CATID *pids; UINT numIds; if (!CATIDsFromPyObject(obCatIds, &pids, &numIds)) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pICR->UnRegisterClassReqCategories(clsid, numIds, pids); PY_INTERFACE_POSTCALL; DeleteCATIDs(pids); if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pICR, IID_ICatRegister); Py_INCREF(Py_None); return Py_None; }
BOOL CATIDsFromPyObject( PyObject *obCatIds, CATID **ppCatIds, UINT *pNumIds) { if (!PySequence_Check(obCatIds)) { PyErr_SetString(PyExc_TypeError, "Object must be a sequence of CATIDs"); return FALSE; } Py_ssize_t len = PyObject_Length(obCatIds); CATID *ids = new CATID[len]; BOOL rc = TRUE; for (Py_ssize_t i=0; rc && i<len; i++) { PyObject *obThis = PySequence_GetItem(obCatIds, i); if (obThis==NULL) { rc = FALSE; break; } if (!PyWinObject_AsIID(obThis, ids+i)) { PyErr_SetString(PyExc_TypeError, "CATID is not valid"); rc = FALSE; } Py_DECREF(obThis); } if (rc) { *ppCatIds = ids; *pNumIds = PyWin_SAFE_DOWNCAST(len, Py_ssize_t, UINT); } else { delete [] ids; } return rc; }
// @pymethod |PyIDocHostUIHandler|TranslateAccelerator|Description of TranslateAccelerator. PyObject *PyIDocHostUIHandler::TranslateAccelerator(PyObject *self, PyObject *args) { IDocHostUIHandler *pIDHUIH = GetI(self); if ( pIDHUIH == NULL ) return NULL; MSG msg; PyObject *oblpMsg; // @pyparm <o PyLPMSG>|lpMsg||Description for lpMsg // @pyparm <o PyIID>|pguidCmdGroup||Description for pguidCmdGroup // @pyparm int|nCmdID||Description for nCmdID PyObject *obpguidCmdGroup; IID guidCmdGroup; DWORD nCmdID; if ( !PyArg_ParseTuple(args, "OOl:TranslateAccelerator", &oblpMsg, &obpguidCmdGroup, &nCmdID) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyWinObject_AsMSG(oblpMsg, &msg)) bPythonIsHappy = FALSE; if (!PyWinObject_AsIID(obpguidCmdGroup, &guidCmdGroup)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIDHUIH->TranslateAccelerator(&msg, &guidCmdGroup, nCmdID ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIDHUIH, IID_IDocHostUIHandler ); return PyInt_FromLong(hr); }
PyObject *PyIGlobalInterfaceTable::GetInterfaceFromGlobal(PyObject *self, PyObject *args) { PyObject *obriid = NULL; DWORD dwCookie; IID riid; void* ppv; HRESULT hr; IGlobalInterfaceTable *pIGIT = GetI(self); if ( pIGIT == NULL ) { return NULL; } if (!PyArg_ParseTuple(args, "lO:GetInterfaceFromGlobal", &dwCookie, &obriid) ) { return NULL; } BOOL bPythonIsHappy = TRUE; if (!PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE; if(!bPythonIsHappy) { return NULL; } PY_INTERFACE_PRECALL; hr = pIGIT->GetInterfaceFromGlobal( dwCookie, riid, &ppv ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) { return PyCom_BuildPyException(hr, pIGIT, IID_IGlobalInterfaceTable ); } return PyCom_PyObjectFromIUnknown((IUnknown*)ppv, riid, FALSE); }
// @pymethod |PyIDebugApplication|FireDebuggerEvent|Fire a generic event to the IApplicationDebugger (if any) PyObject *PyIDebugApplication::FireDebuggerEvent(PyObject *self, PyObject *args) { PY_INTERFACE_METHOD; IDebugApplication *pIDA = GetI(self); if ( pIDA == NULL ) return NULL; // @pyparm <o PyIIID>|guid||A GUID. // @pyparm <o PyIUnknown>|unknown||An unknown object. PyObject *obguid, *obunk; if ( !PyArg_ParseTuple(args, "OO:FireDebuggerEvent", &obguid, &obunk) ) return NULL; BOOL bPythonIsHappy = TRUE; IUnknown *punk; IID iid; if (!PyWinObject_AsIID(obguid, &iid)) bPythonIsHappy = FALSE; if (!PyCom_InterfaceFromPyInstanceOrObject(obunk, IID_IUnknown, (void **)&punk, FALSE /* bNoneOK */)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pIDA->FireDebuggerEvent( iid, punk ); punk->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return SetPythonCOMError(self,hr); Py_INCREF(Py_None); return Py_None; }
// @pymethod <o PyUnicode>|pythoncom|UnRegisterTypeLib|Unregister a Type Library. PyObject *pythoncom_unregistertypelib(PyObject *self, PyObject *args) { PyObject *obIID; int major, minor; LCID lcid = LOCALE_USER_DEFAULT; SYSKIND syskind = SYS_WIN32; // @pyparm <o PyIID>|iid||The IID of the type library. // @pyparm int|versionMajor||The major version number of the library // @pyparm int|versionMinor||The minor version number of the library // @pyparm int|lcid|LOCALE_USER_DEFAULT|The locale ID to use. // @pyparm int|syskind|SYS_WIN32|The target operating system. if (!PyArg_ParseTuple(args, "Oii|ii", &obIID, &major, &minor, &lcid, &syskind)) return NULL; CLSID clsid; if (!PyWinObject_AsIID(obIID, &clsid)) return NULL; PY_INTERFACE_PRECALL; // WARNING: Requires Win95 OSR2 or later!!! HRESULT hr = UnRegisterTypeLib(clsid, major, minor, lcid, syskind); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); Py_INCREF(Py_None); return Py_None; // @comm Removes type library information from the system registry. // Use this API to allow applications to properly uninstall themselves. // In-process objects typically call this API from DllUnregisterServer. }
// @pymethod |pythoncom|WriteClassStm|Writes a CLSID to a stream. PyObject *pythoncom_WriteClassStm(PyObject *self, PyObject *args) { PyObject *obStm; PyObject *obCLSID; if (!PyArg_ParseTuple(args, "OO:WriteClassStm", &obStm, // @pyparm <o PyIStream>|Stm||An IStream interface &obCLSID)) // @pyparm <o PyIID>|clsid||The IID to write return NULL; CLSID clsid; if (!PyWinObject_AsIID(obCLSID, &clsid)) return NULL; IStream *pStm; if (!PyCom_InterfaceFromPyObject(obStm, IID_IStream, (void **)&pStm, FALSE)) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = WriteClassStm(pStm, clsid); pStm->Release(); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); Py_INCREF(Py_None); return Py_None; }
// @pymethod <o PyUNICODE>|pythoncom|FmtIdToPropStgName|Converts a FMTID to its stream name PyObject *pythoncom_FmtIdToPropStgName(PyObject *self, PyObject *args) { // @pyparm <o PyIID>|fmtid||Format id - a property storage GUID (FMTID_* IIDs) HRESULT err; WCHAR oszName[CCH_MAX_PROPSTG_NAME]; FMTID fmtid; PyObject *obfmtid=NULL; typedef HRESULT (WINAPI * PFNFmtIdToPropStgName)(const FMTID*, LPOLESTR); static PFNFmtIdToPropStgName pfnFmtIdToPropStgName=NULL; static BOOL pfnchecked=FALSE; if (!pfnchecked){ if (ole32==NULL) ole32=GetModuleHandle(_T("Ole32.dll")); if (ole32!=NULL) pfnFmtIdToPropStgName = (PFNFmtIdToPropStgName)GetProcAddress(ole32, "FmtIdToPropStgName"); pfnchecked=TRUE; } if (pfnFmtIdToPropStgName==NULL) return PyErr_Format(PyExc_NotImplementedError,"FmtIdToPropStgName is not available on this platform"); if (!PyArg_ParseTuple(args, "O:FmtIdToPropStgName", &obfmtid)) return NULL; if (!PyWinObject_AsIID(obfmtid, &fmtid)) return NULL; PY_INTERFACE_PRECALL; err = (*pfnFmtIdToPropStgName)(&fmtid, oszName); PY_INTERFACE_POSTCALL; if (err!=S_OK) return PyCom_BuildPyException(err); return PyWinObject_FromWCHAR(oszName); }
// @pymethod |pythoncom|WriteClassStg|Writes a CLSID to a storage object PyObject *pythoncom_WriteClassStg(PyObject *self, PyObject *args) { PyObject *obStg; PyObject *obCLSID; if (!PyArg_ParseTuple(args, "OO:WriteClassStg", &obStg, // @pyparm <o PyIStorage>|storage||Storage object into which CLSID will be written. &obCLSID)) // @pyparm <o PyIID>|iid||The IID to write return NULL; CLSID clsid; if (!PyWinObject_AsIID(obCLSID, &clsid)) return NULL; IStorage *pStorage; if (!PyCom_InterfaceFromPyObject(obStg, IID_IStorage, (void **)&pStorage, FALSE)) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = WriteClassStg(pStorage, clsid); pStorage->Release(); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); Py_INCREF(Py_None); return Py_None; }
// @pymethod <o PyIUnknown>|PyIShellView|GetItemObject|Description of GetItemObject. PyObject *PyIShellView::GetItemObject(PyObject *self, PyObject *args) { IShellView *pISV = GetI(self); if ( pISV == NULL ) return NULL; // @pyparm int|uItem||Description for uItem // @pyparm <o PyIID>|riid||Description for riid PyObject *obriid; UINT uItem; IID riid; IUnknown *ppv; if ( !PyArg_ParseTuple(args, "iO:GetItemObject", &uItem, &obriid) ) return NULL; BOOL bPythonIsHappy = TRUE; if (!PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISV->GetItemObject( uItem, riid, (void **)&ppv ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISV, IID_IShellView ); PyObject *obppv; obppv = PyCom_PyObjectFromIUnknown(ppv, riid, FALSE); PyObject *pyretval = Py_BuildValue("O", obppv); Py_XDECREF(obppv); return pyretval; }
/* static */ PyObject *PyIActiveScript::AddTypeLib(PyObject *self, PyObject *args) { PY_INTERFACE_METHOD; PyObject *obiid; int major; int minor; int flags; if ( !PyArg_ParseTuple(args, "Oiii:AddTypeLib", &obiid, &major, &minor, &flags) ) return NULL; CLSID libiid; if ( !PyWinObject_AsIID(obiid, &libiid) ) return NULL; IActiveScript *pIAS = GetI(self); if ( pIAS == NULL ) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pIAS->AddTypeLib(libiid, (DWORD)major, (DWORD)minor, (DWORD)flags); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return SetPythonCOMError(self, hr); Py_INCREF(Py_None); return Py_None; }
// @pymethod <o PyITypeLib>|pythoncom|LoadRegTypeLib|Loads a registered type library. PyObject *pythoncom_loadregtypelib(PyObject *self, PyObject *args) { PyObject *obIID; int major, minor; LCID lcid = LOCALE_USER_DEFAULT; // @pyparm <o PyIID>|iid||The IID of the type library. // @pyparm int|versionMajor||The major version number of the library // @pyparm int|versionMinor||The minor version number of the library // @pyparm int|lcid|LOCALE_USER_DEFAULT|The locale ID to use. if (!PyArg_ParseTuple(args, "Oii|i:LoadRegTypeLib", &obIID, &major, &minor, &lcid)) return NULL; CLSID clsid; if (!PyWinObject_AsIID(obIID, &clsid)) return NULL; ITypeLib *ptl; PY_INTERFACE_PRECALL; SCODE sc = LoadRegTypeLib(clsid, major, minor, lcid, &ptl); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc); return PyCom_PyObjectFromIUnknown(ptl, IID_ITypeLib); // @comm LoadRegTypeLib compares the requested version numbers against those found in the system registry, and takes one of the following actions:<nl> // If one of the registered libraries exactly matches both the requested major and minor version numbers, then that type library is loaded. <nl> // If one or more registered type libraries exactly match the requested major version number, and has a greater minor version number than that requested, the one with the greatest minor version number is loaded. <nl> // If none of the registered type libraries exactly match the requested major version number (or if none of those that do exactly match the major version number also have a minor version number greater than or equal to the requested minor version number), then LoadRegTypeLib returns an error. }
// @pymethod |PyIStorage|CopyTo|Copies the entire contents of an open storage object to another storage object. PyObject *PyIStorage::CopyTo(PyObject *self, PyObject *args) { IStorage *pIS = GetI(self); if ( pIS == NULL ) return NULL; // @pyparm [<o PyIID>,]|rgiidExclude||List of IID's to be excluded. // @pyparm <o SNB>|snbExclude||Reserved for later - Must be None // @pyparm <o PyIStorage>|stgDest||The open storage object into which this storage object is to be copied. // The destination storage object can be a different implementation of the <o PyIStorage> interface from the source storage object. // Thus, <om IStorage::CopyTo> can only use publicly available methods of the destination storage object. // If stgDest is open in transacted mode, it can be reverted by calling its <om PyIStorage::Revert> method. DWORD ciidExclude = 0; PyObject *obSeqExclude; PyObject *obpstgDest; char *temp; if ( !PyArg_ParseTuple(args, "OzO:CopyTo", &obSeqExclude, &temp, &obpstgDest) ) return NULL; IID *pExclude; if (obSeqExclude==Py_None) pExclude = NULL; else { if (!PySequence_Check(obSeqExclude)) { PyErr_SetString(PyExc_TypeError, "Argument 1 must be a sequence of IID's, or None"); return NULL; } ciidExclude = PySequence_Length(obSeqExclude); pExclude = new IID[ciidExclude]; if (pExclude==NULL) { PyErr_SetString(PyExc_MemoryError, "Allocating array of IID's"); return NULL; } for (DWORD i=0;i<ciidExclude;i++) { PyObject *ob = PySequence_GetItem(obSeqExclude, (int)i); BOOL ok = PyWinObject_AsIID(ob, pExclude+i); Py_XDECREF(ob); if (!ok) { delete [] pExclude; return NULL; } } } IStorage *pstgDest; BOOL bPythonIsHappy = TRUE; if (!PyCom_InterfaceFromPyObject(obpstgDest, IID_IStorage, (void **)&pstgDest, FALSE /* bNoneOK */)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) { return NULL; delete [] pExclude; } PY_INTERFACE_PRECALL; HRESULT hr = pIS->CopyTo( ciidExclude, pExclude, NULL, pstgDest ); delete [] pExclude; pstgDest->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIS, IID_IStorage); Py_INCREF(Py_None); return Py_None; }
// @pymethod <o PyUnicode>|pythoncom|QueryPathOfRegTypeLib|Retrieves the path of a registered type library. PyObject *pythoncom_querypathofregtypelib(PyObject *self, PyObject *args) { PyObject *obIID; int major, minor; LCID lcid = LOCALE_USER_DEFAULT; // @pyparm <o PyIID>|iid||The IID of the type library. // @pyparm int|versionMajor||The major version number of the library // @pyparm int|versionMinor||The minor version number of the library // @pyparm int|lcid|LOCALE_USER_DEFAULT|The locale ID to use. if (!PyArg_ParseTuple(args, "Oii|i", &obIID, &major, &minor, &lcid)) return NULL; CLSID clsid; if (!PyWinObject_AsIID(obIID, &clsid)) return NULL; BSTR result; PY_INTERFACE_PRECALL; HRESULT hr = QueryPathOfRegTypeLib(clsid, major, minor, lcid, &result); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); return PyWinObject_FromBstr( result, TRUE ); }
// @pymethod |PyIContext|SetProperty|Sets a property on the context PyObject *PyIContext::SetProperty(PyObject *self, PyObject *args) { IContext *pIC = GetI(self); if ( pIC == NULL ) return NULL; // @pyparm <o PyIID>|rpolicyId||GUID identifying the property to be set // @pyparm int|flags||Reserved, use only 0 // @pyparm <o PyIUnknown>|pUnk||The property value CPFLAGS flags; PyObject *obrpolicyId; PyObject *obUnk; IID rpolicyId; IUnknown * pUnk; if ( !PyArg_ParseTuple(args, "OkO:SetProperty", &obrpolicyId, &flags, &obUnk) ) return NULL; if (!PyWinObject_AsIID(obrpolicyId, &rpolicyId)) return NULL; if (!PyCom_InterfaceFromPyInstanceOrObject(obUnk, IID_IUnknown, (void **)&pUnk, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIC->SetProperty( rpolicyId, flags, pUnk ); pUnk->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIC, IID_IContext ); Py_INCREF(Py_None); return Py_None; }
// @pymethod |PyICatRegister|RegisterCategories|Registers one or more component categories. Each component category consists of a CATID and a list of locale-dependent description strings. PyObject *PyICatRegister::RegisterCategories(PyObject *self, PyObject *args) { PyObject *obCatList; // @pyparm [ (<o PyIID>, int, string), ...]|[ (catId, lcid, description), ...]||A sequence of category descriptions. if ( !PyArg_ParseTuple(args, "O:RegisterCategories", &obCatList) ) return NULL; ICatRegister *pICR = GetI(self); if ( pICR == NULL ) return NULL; if (!PySequence_Check(obCatList)) { PyErr_SetString(PyExc_TypeError, "Argument must be a list of CATEGORYINFO tuples"); return NULL; } Py_ssize_t noInfos = PyObject_Length(obCatList); CATEGORYINFO *infos = new CATEGORYINFO [noInfos]; if (infos==NULL) { PyErr_SetString(PyExc_MemoryError, "Allocating CATEGORYINFO array"); return NULL; } for (Py_ssize_t i=0; i<noInfos; i++) { PyObject *obCatId; PyObject *obThis = PySequence_GetItem(obCatList, i); if (obThis==NULL) return NULL; BOOL ok = TRUE; PyObject *obDesc; if (!PyArg_ParseTuple(obThis, "OlO", &obCatId, (long *)&infos[i].lcid, &obDesc)) { Py_DECREF(obThis); PyErr_SetString(PyExc_TypeError, "Category infos must be CATID, lcid, description"); delete [] infos; return NULL; } Py_DECREF(obThis); if (!PyWinObject_AsIID(obCatId, &infos[i].catid)) { delete [] infos; return NULL; } OLECHAR *oc; if (!PyWinObject_AsWCHAR(obDesc, &oc, FALSE)) { delete [] infos; return NULL; } wcsncpy(infos[i].szDescription, oc, sizeof(infos->szDescription)/sizeof(infos->szDescription[0])); PyWinObject_FreeWCHAR(oc); } PY_INTERFACE_PRECALL; HRESULT hr = pICR->RegisterCategories(PyWin_SAFE_DOWNCAST(noInfos, Py_ssize_t, ULONG), infos); PY_INTERFACE_POSTCALL; delete [] infos; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pICR, IID_ICatRegister); Py_INCREF(Py_None); return Py_None; }
// @pymethod <o PyIStorage>|pythoncom|StgOpenStorageEx|Advanced version of StgOpenStorage, win2k or better PyObject *pythoncom_StgOpenStorageEx(PyObject *self, PyObject *args) { #ifndef NO_PYCOM_STGOPENSTORAGEEX typedef HRESULT (WINAPI *PFNStgOpenStorageEx)(WCHAR *, DWORD, DWORD, DWORD, STGOPTIONS *, void *, REFIID, void **);; static PFNStgOpenStorageEx myStgOpenStorageEx = NULL; if (myStgOpenStorageEx==NULL) { // Haven't tried to fetch it yet. myStgOpenStorageEx = (PFNStgOpenStorageEx)-1; if (ole32==NULL) ole32=GetModuleHandle(_T("Ole32.dll")); if (ole32!=NULL){ FARPROC fp = GetProcAddress(ole32,"StgOpenStorageEx"); if (fp!=NULL) myStgOpenStorageEx=(PFNStgOpenStorageEx)fp; } } if (myStgOpenStorageEx == (PFNStgOpenStorageEx)-1) return PyErr_Format(PyExc_NotImplementedError,"StgOpenStorageEx not supported by this version of Windows"); PyObject *obfname=NULL, *obriid=NULL, *obstgoptions=NULL; WCHAR *fname; DWORD mode=0, attrs=0; VOID *reserved=NULL; DWORD stgfmt; IID riid; STGOPTIONS *pstgoptions=NULL; HRESULT err; void *intptr; if (!PyArg_ParseTuple(args, "OiiiO|O:StgOpenStorageEx", &obfname, //@pyparm string|name||Name of the stream or file to open &mode, // @pyparm int|grfmode||open flags &stgfmt, // @pyparm int|stgfmt||Storage format (STGFMT_STORAGE,STGFMT_FILE,STGFMT_ANY, or STGFMT_DOCFILE) &attrs, // @pyparm int|grfAttrs||Reserved, must be 0 &obriid, // @pyparm IID|riid||Interface id to return, IStorage or IPropertySetStorage &obstgoptions)) //@pyparm <o dict>|pStgOptions||Dictionary representing STGOPTIONS struct (only used with STGFMT_DOCFILE) return NULL; if (!PyWinObject_AsIID(obriid, &riid)) return NULL; if(!PyCom_PyObjectAsSTGOPTIONS(obstgoptions, &pstgoptions)) return NULL; if (!PyWinObject_AsWCHAR(obfname,&fname)) return NULL; PY_INTERFACE_PRECALL; err = (*myStgOpenStorageEx)(fname, mode, stgfmt, attrs, NULL, reserved, riid, &intptr); PY_INTERFACE_POSTCALL; if (pstgoptions) delete(pstgoptions); PyWinObject_FreeWCHAR(fname); if (FAILED(err)) return PyCom_BuildPyException(err); return PyCom_PyObjectFromIUnknown((IUnknown *)intptr, riid, FALSE); #else return PyErr_Format(PyExc_NotImplementedError,"StgOpenStorageEx not supported by this version of Windows"); #endif // NO_PYCOM_STGOPENSTORAGEEX }
// @pymethod <o PyITypeInfo>|PyITypeLib|GetTypeInfoOfGuid|Retrieves the type info of the specified GUID. static PyObject *typelib_gettypeinfoofguid(PyObject *self, PyObject *args) { PyObject *obguid; // @pyparm <o PyIID>|iid||GUID of the type description. if (!PyArg_ParseTuple(args, "O:GetTypeInfoOfGuid", &obguid)) return NULL; GUID guid; if (!PyWinObject_AsIID(obguid, &guid)) return NULL; return ((PyITypeLib*)self)->GetTypeInfoOfGuid(guid); }
STDMETHODIMP PyGConnectionPoint::GetConnectionInterface(IID *pIID) { PY_GATEWAY_METHOD; if (pIID==NULL) return E_POINTER; PyObject *result; HRESULT hr = InvokeViaPolicy("GetConnectionInterface", &result, NULL); if (FAILED(hr)) return hr; if (!PyWinObject_AsIID(result, pIID)) hr = PyCom_SetCOMErrorFromPyException(IID_IConnectionPoint); Py_XDECREF(result); return hr; }
STDMETHODIMP PyGExplorerCommand::GetCanonicalName( /* [out] */ GUID * pguidCommandName) { PY_GATEWAY_METHOD; PyObject *result; HRESULT hr=InvokeViaPolicy("GetCanonicalName", &result); if (FAILED(hr)) return hr; // Process the Python results, and convert back to the real params if (!PyWinObject_AsIID(result, pguidCommandName)) hr = PyCom_SetAndLogCOMErrorFromPyException("GetCanonicalName", IID_IExplorerCommand); Py_DECREF(result); return hr; }
// @pymethod <o PyIUnknown>|PyIMoniker|BindToStorage|Retrieves an interface object to the storage that contains the object identified by the moniker. PyObject *PyIMoniker::BindToStorage(PyObject *self, PyObject *args) { // @pyparm <o PyIBindCtx>|bindCtx||bind context object to be used. // @pyparm <o PyIMoniker>|moniker||If the moniker is part of a composite moniker, otherwise None // @pyparm <o IID>|iidResult||IID of the result object. PyObject *obBindCtx; PyObject *obMoniker; PyObject *obIID; if (!PyArg_ParseTuple(args, "OOO:BindToStorage", &obBindCtx, &obMoniker, &obIID)) return NULL; IMoniker *pMy = GetI(self); if (pMy==NULL) return NULL; IBindCtx *pBindCtx; if (!PyCom_InterfaceFromPyInstanceOrObject(obBindCtx, IID_IBindCtx, (void **)&pBindCtx, FALSE)) return NULL; IMoniker *pMonLeft = NULL; if (obMoniker!=Py_None) { if (!PyCom_InterfaceFromPyInstanceOrObject(obMoniker, IID_IMoniker, (void **)&pMonLeft, FALSE)) { PY_INTERFACE_PRECALL; pBindCtx->Release(); PY_INTERFACE_POSTCALL; return NULL; } } IID iid; if (!PyWinObject_AsIID(obIID, &iid)) { PY_INTERFACE_PRECALL; pBindCtx->Release(); if (pMonLeft) pMonLeft->Release(); PY_INTERFACE_POSTCALL; return NULL; } void *pResult = NULL; PY_INTERFACE_PRECALL; HRESULT hr = pMy->BindToStorage(pBindCtx, pMonLeft, iid, &pResult ); pBindCtx->Release(); if (pMonLeft) pMonLeft->Release(); PY_INTERFACE_POSTCALL; if (S_OK!=hr) // S_OK only acceptable return PyCom_BuildPyException(hr, pMy, IID_IMoniker); return PyCom_PyObjectFromIUnknown((IUnknown *)pResult, iid, FALSE ); }
STDMETHODIMP PyGDebugDocumentInfo::GetDocumentClassId( /* [out] */ GUID __RPC_FAR * pclsidDocument) { PY_GATEWAY_METHOD; PyObject *result; HRESULT hr=InvokeViaPolicy("GetDocumentClassId", &result); if (FAILED(hr)) return hr; // Process the Python results, and convert back to the real params PyObject *obpclsidDocument; if (!PyArg_Parse(result, "O" , &obpclsidDocument)) return PyCom_HandlePythonFailureToCOM(/*pexcepinfo*/); BOOL bPythonIsHappy = TRUE; if (!PyWinObject_AsIID(obpclsidDocument, pclsidDocument)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) hr = PyCom_HandlePythonFailureToCOM(/*pexcepinfo*/); Py_DECREF(result); return hr; }
STDMETHODIMP PyGCategoryProvider::GetCategoryForSCID( /* [in] */ __RPC__in const SHCOLUMNID * pscid, /* [out] */ __RPC__out GUID * pguid) { PY_GATEWAY_METHOD; PyObject *obpscid = PyObject_FromSHCOLUMNID(pscid); if (obpscid==NULL) return MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetCategoryForSCID"); PyObject *result; HRESULT hr=InvokeViaPolicy("GetCategoryForSCID", &result, "(O)", obpscid); Py_DECREF(obpscid); if (FAILED(hr)) return hr; if (!PyWinObject_AsIID(result, pguid)) hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetCategoryForSCID"); Py_DECREF(result); return hr; }
////////////////////////////////////////////////////////////// // // BINDINFO support // BOOL PyObject_AsBINDINFO(PyObject *ob, BINDINFO *pPD) { BOOL ok = FALSE; memset(pPD, 0, sizeof(BINDINFO)); pPD->cbSize = sizeof(BINDINFO); PyObject *obExtra = Py_None; PyObject *obSTGM = Py_None; PyObject *obCustomVerb = Py_None; PyObject *obSA = Py_None; PyObject *obIID = Py_None; PyObject *obUnk = Py_None; if (!PyArg_ParseTuple(ob, "|OOllOlllOOOl", &obExtra, &obSTGM, &pPD->grfBindInfoF, &pPD->dwBindVerb, &obCustomVerb, &pPD->dwOptions, &pPD->dwOptionsFlags, &pPD->dwCodePage, &obSA, &obIID, &obUnk, &pPD->dwReserved)) goto done; if (!PyWinObject_AsTaskAllocatedWCHAR(obExtra, &pPD->szExtraInfo, /*bNoneOK=*/TRUE, NULL)) goto done; if (obSTGM != Py_None) { PyErr_SetString(PyExc_TypeError, "Sorry - dont support STGMEDIUM yet - must be None"); goto done; } if (!PyWinObject_AsTaskAllocatedWCHAR(obCustomVerb, &pPD->szCustomVerb, /*bNoneOK=*/TRUE, NULL)) goto done; SECURITY_ATTRIBUTES *pSA; if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE)) goto done; pPD->securityAttributes = *pSA; if (obIID != Py_None && !PyWinObject_AsIID(obIID, &pPD->iid)) goto done; if (!PyCom_InterfaceFromPyInstanceOrObject(obUnk, pPD->iid, (void **)&pPD->pUnk, TRUE)) goto done; ok = TRUE; done: // todo: cleanup if !ok return ok; }