// @pymethod |PyIBackgroundCopyJob|SetProxySettings|Description of SetProxySettings. PyObject *PyIBackgroundCopyJob::SetProxySettings(PyObject *self, PyObject *args) { IBackgroundCopyJob *pIBCJ = GetI(self); if ( pIBCJ == NULL ) return NULL; BG_JOB_PROXY_USAGE ProxyUsage; // @pyparm int|ProxyUsage||Description for ProxyUsage WCHAR * ProxyList; PyObject *obProxyList; // @pyparm unicode|ProxyList||Description for ProxyList WCHAR * ProxyBypassList; PyObject *obProxyBypassList; // @pyparm unicode|ProxyBypassList||Description for ProxyBypassList if ( !PyArg_ParseTuple(args, "lOO:SetProxySettings", &ProxyUsage, &obProxyList, &obProxyBypassList) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyWinObject_AsWCHAR( obProxyList, &ProxyList, TRUE )) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR( obProxyBypassList, &ProxyBypassList, TRUE )) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIBCJ->SetProxySettings( ProxyUsage, ProxyList, ProxyBypassList ); PyWinObject_FreeWCHAR(ProxyList); PyWinObject_FreeWCHAR(ProxyBypassList); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIBCJ, IID_IBackgroundCopyJob ); Py_INCREF(Py_None); return Py_None; }
// @pymethod int|win32ts|WTSSendMessage|Sends a popup message to a terminal services session // @rdesc Returns one of IDABORT,IDCANCEL,IDIGNORE,IDNO,IDOK,IDRETRY,IDYES,IDASYNC,IDTIMEOUT, static PyObject *PyWTSSendMessage(PyObject *self, PyObject *args, PyObject *kwargs) { static char *keywords[]={"Server","SessionId","Title","Message","Style","Timeout","Wait", NULL}; PyObject *obh=NULL; HANDLE h; DWORD SessionId, TitleLen, MessageLen, Style, Timeout, Response; WCHAR *Title=NULL, *Message=NULL; PyObject *obTitle, *obMessage, *ret=NULL; BOOL Wait; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OkOOkkl:WTSSendMessage", keywords, &obh, // @pyparm <o PyHANDLE>|Server|WTS_CURRENT_SERVER_HANDLE|Handle to a terminal server, or WTS_CURRENT_SERVER_HANDLE &SessionId, // @pyparm int|SessionId||Terminal services session id &obTitle, // @pyparm <o PyUnicode>|Title||Title of dialog &obMessage, // @pyparm <o PyUnicode>|Message||Message to be displayed &Style, // @pyparm int|Style||Usually MB_OK &Timeout, // @pyparm int|Timeout||Seconds to wait before returning (only used if Wait is True) &Wait)) // @pyparm boolean|Wait||Specifies if function should wait for user input before returning return NULL; if (PyWinObject_AsHANDLE(obh, &h) &&PyWinObject_AsWCHAR(obTitle, &Title, FALSE, &TitleLen) &&PyWinObject_AsWCHAR(obMessage, &Message, FALSE, &MessageLen)){ if (WTSSendMessage(h, SessionId, Title, TitleLen*sizeof(WCHAR), Message, MessageLen*sizeof(WCHAR), Style, Timeout, &Response, Wait)) ret=PyLong_FromUnsignedLong(Response); else PyWin_SetAPIError("WTSSendMessage"); } PyWinObject_FreeWCHAR(Title); PyWinObject_FreeWCHAR(Message); return ret; }
// @pymethod ([dict, ...], total, resumeHandle)|win32net|NetUseEnum|Retrieves information about transport protocols that are currently managed by the redirector // @rdesc The result is a list of items read (with each item being a dictionary of format // <o PyUSE_INFO_*>, depending on the level parameter), // the total available, and a new "resume handle". The first time you call // this function, you should pass zero for the resume handle. If more data // is available than what was returned, a new non-zero resume handle will be // returned, which can be used to call the function again to fetch more data. // This process may repeat, each time with a new resume handle, until zero is // returned for the new handle, indicating all the data has been read. PyObject * PyNetUseEnum(PyObject *self, PyObject *args) { WCHAR *szServer = NULL, *szDomain = NULL; PyObject *obServer, *obDomain = Py_None; PyObject *ret = NULL; PyNET_STRUCT *pInfo; DWORD err; DWORD dwPrefLen = MAX_PREFERRED_LENGTH; DWORD level; BOOL ok = FALSE; DWORD resumeHandle = 0; DWORD numRead, i; PyObject *list; BYTE *buf = NULL; DWORD totalEntries = 0; // @pyparm string/<o PyUnicode>|server||The name of the server to execute on, or None. // @pyparm int|level||The level of data required. Currently levels 0, 1 and // 2 are supported. // @pyparm int|resumeHandle|0|A resume handle. See the return description for more information. // @pyparm int|prefLen|MAX_PREFERRED_LENGTH|The preferred length of the data buffer. if (!PyArg_ParseTuple(args, "Oi|ii", &obServer, &level, &resumeHandle, &dwPrefLen)) return NULL; if (!PyWinObject_AsWCHAR(obServer, &szServer, TRUE)) goto done; if (!PyWinObject_AsWCHAR(obDomain, &szDomain, TRUE)) goto done; if (!FindNET_STRUCT(level, use_infos, &pInfo)) goto done; err = NetUseEnum(szServer, level, &buf, dwPrefLen, &numRead, &totalEntries, &resumeHandle); if (err!=0 && err != ERROR_MORE_DATA) { ReturnNetError("NetUseEnum",err); goto done; } list = PyList_New(numRead); if (list==NULL) goto done; for (i=0;i<numRead;i++) { PyObject *sub = PyObject_FromNET_STRUCT(pInfo, buf+(i*pInfo->structsize)); if (sub==NULL) goto done; PyList_SetItem(list, i, sub); } resumeHandle = err==0 ? 0 : resumeHandle; ret = Py_BuildValue("Oll", list, totalEntries, resumeHandle); Py_DECREF(list); ok = TRUE; done: if (buf) NetApiBufferFree(buf); if (!ok) { Py_XDECREF(ret); ret = NULL; } PyWinObject_FreeWCHAR(szServer); return ret; // @pyseeapi NetUseEnum }
// @pymethod object|win32ts|WTSQueryUserConfig|Returns user configuration // @rdesc The type of the returned value is dependent on the config class requested static PyObject *PyWTSQueryUserConfig(PyObject *self, PyObject *args, PyObject *kwargs) { static char *keywords[]={"ServerName","UserName","WTSConfigClass",NULL}; WCHAR *ServerName=NULL, *UserName=NULL; PyObject *obServerName, *obUserName, *ret=NULL; WTS_CONFIG_CLASS WTSConfigClass; LPWSTR buf=NULL; DWORD bufsize=0; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOk:WTSQueryUserConfig", keywords, &obServerName, // @pyparm <o PyUnicode>|ServerName||Name ot terminal server &obUserName, // @pyparm <o PyUnicode>|UserName||Name of user &WTSConfigClass)) // @pyparm int|ConfigClass||Type of information to be returned, win32ts.WTSUserConfig* return NULL; if (PyWinObject_AsWCHAR(obServerName, &ServerName, TRUE) &&PyWinObject_AsWCHAR(obUserName, &UserName, FALSE)) if (!WTSQueryUserConfig(ServerName, UserName, WTSConfigClass, &buf, &bufsize)) PyWin_SetAPIError("WTSQueryUserConfig"); else switch(WTSConfigClass){ // @flagh ConfigClass|Returned value case WTSUserConfigInitialProgram: // @flag WTSUserConfigInitialProgram|Unicode string, program to be run when user logs on case WTSUserConfigWorkingDirectory: // @flag WTSUserConfigWorkingDirectory|Unicode string, working dir for initial program case WTSUserConfigModemCallbackPhoneNumber: // @flag WTSUserConfigModemCallbackPhoneNumber|Unicode string case WTSUserConfigTerminalServerProfilePath: // @flag WTSUserConfigTerminalServerProfilePath|Unicode string case WTSUserConfigTerminalServerHomeDir: // @flag WTSUserConfigTerminalServerHomeDir|Unicode string case WTSUserConfigTerminalServerHomeDirDrive: // @flag WTSUserConfigTerminalServerHomeDirDrive|Unicode string ret=PyWinObject_FromWCHAR(buf); break; case WTSUserConfigfInheritInitialProgram: // @flag WTSUserConfigfInheritInitialProgram|Int case WTSUserConfigfAllowLogonTerminalServer: // @flag WTSUserConfigfAllowLogonTerminalServer|Int, 1 if user can log on thru Terminal Service case WTSUserConfigTimeoutSettingsConnections: // @flag WTSUserConfigTimeoutSettingsConnections |Int, max connection time (ms) case WTSUserConfigTimeoutSettingsDisconnections:// @flag WTSUserConfigTimeoutSettingsDisconnections|Int case WTSUserConfigTimeoutSettingsIdle: // @flag WTSUserConfigTimeoutSettingsIdle|Int, max idle time (ms) case WTSUserConfigfDeviceClientDrives: // @flag WTSUserConfigfDeviceClientDrives|Int case WTSUserConfigfDeviceClientPrinters: // @flag WTSUserConfigfDeviceClientPrinters|Int case WTSUserConfigfDeviceClientDefaultPrinter: // @flag WTSUserConfigfDeviceClientDefaultPrinter|Int case WTSUserConfigBrokenTimeoutSettings: // @flag WTSUserConfigBrokenTimeoutSettings|Int case WTSUserConfigReconnectSettings: // @flag WTSUserConfigReconnectSettings|Int case WTSUserConfigModemCallbackSettings: // @flag WTSUserConfigModemCallbackSettings|Int case WTSUserConfigShadowingSettings: // @flag WTSUserConfigShadowingSettings|Int, indicates if user's session my be monitored case WTSUserConfigfTerminalServerRemoteHomeDir: // @flag WTSUserConfigfTerminalServerRemoteHomeDir|Int, ret=PyLong_FromUnsignedLong(*(DWORD *)buf); break; default: PyErr_SetString(PyExc_NotImplementedError,"Config class not supported yet"); } PyWinObject_FreeWCHAR(ServerName); PyWinObject_FreeWCHAR(UserName); if (buf) WTSFreeMemory(buf); return ret; }
// IEmptyVolumeCache2 // @object PyIEmptyVolumeCache2|See also <o PyIEmptyVolumeCache> // @pymeth PyIEmptyVolumeCache|Deactivate // @pymethod |PyIEmptyVolumeCache2|InitializeEx| STDMETHODIMP PyGEmptyVolumeCache2::InitializeEx( /* [in] */ HKEY hkRegKey, /* [in] */ LPCWSTR pcwszVolume, /* [in] */ LPCWSTR pcwszKeyName, /* [out] */ LPWSTR * ppwszDisplayName, /* [out] */ LPWSTR * ppwszDescription, /* [out] */ LPWSTR * ppwszBtnText, /* [out] */ DWORD * pdwFlags) { PY_GATEWAY_METHOD; BOOL bPythonIsHappy = TRUE; ULONG dwFlags; HRESULT hr; PyObject *result; PyObject *obppwszDisplayName; PyObject *obppwszDescription; PyObject *obppwszBtnText; PyObject *obpcwszVolume = NULL; PyObject *obpcwszKeyName = NULL; PyObject *obhkRegKey = PyWinObject_FromHKEY(hkRegKey); if (!obhkRegKey) goto args_failed; if (!(obpcwszVolume = MakeOLECHARToObj(pcwszVolume))) goto args_failed; if (!(obpcwszKeyName = MakeOLECHARToObj(pcwszKeyName))) goto args_failed; hr=InvokeViaPolicy("InitializeEx", &result, "NNNk", obhkRegKey, obpcwszVolume, obpcwszKeyName, *pdwFlags); // NOTE: From here, do *not* exit via args_failed - the args have been cleaned up if (FAILED(hr)) return hr; // Process the Python results, and convert back to the real params if (!PyTuple_Check(result)) { PyErr_Format(PyExc_TypeError, "Initialize must return a tuple of (unicode, unicode, unicode, long) - got '%s'", result->ob_type->tp_name); bPythonIsHappy = FALSE; } if (bPythonIsHappy && !PyArg_ParseTuple(result, "OOOl" , &obppwszDisplayName, &obppwszDescription, &obppwszBtnText, &dwFlags)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR(obppwszDisplayName, ppwszDisplayName)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR(obppwszDescription, ppwszDescription)) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyWinObject_AsWCHAR(obppwszBtnText, ppwszBtnText)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) hr = PyCom_SetAndLogCOMErrorFromPyException("InitializeEx", IID_IEmptyVolumeCache); if (pdwFlags) *pdwFlags = dwFlags; Py_DECREF(result); return hr; args_failed: // only hit on error convering input args, not normal exit. Py_XDECREF(obhkRegKey); Py_XDECREF(obpcwszVolume); Py_XDECREF(obpcwszKeyName); return MAKE_PYCOM_GATEWAY_FAILURE_CODE("InitializeEx"); }
BOOL PyWinObject_AsMAPIStr(PyObject *stringObject, LPTSTR *pResult, BOOL asUnicode, BOOL bNoneOK /*= FALSE*/, DWORD *pResultLen /* = NULL */) { #if PY_MAJOR_VERSION >= 3 if (asUnicode) return PyWinObject_AsWCHAR(stringObject, (LPWSTR *)pResult, bNoneOK, pResultLen); else return PyWinObject_AsString(stringObject, (LPSTR *)pResult, bNoneOK, pResultLen); #else if (asUnicode && PyUnicode_Check(stringObject)) return PyWinObject_AsWCHAR(stringObject, (LPWSTR *)pResult, bNoneOK, pResultLen); // allows already encoded string pass-through workaround (backwards compat) return PyWinObject_AsString(stringObject, (LPSTR *)pResult, bNoneOK, pResultLen); #endif }
// @pymethod |PyICustomDestinationList|AppendCategory|Adds a custom category to the jump list PyObject *PyICustomDestinationList::AppendCategory(PyObject *self, PyObject *args) { ICustomDestinationList *pICDL = GetI(self); if ( pICDL == NULL ) return NULL; TmpWCHAR Category; PyObject *obCategory, *obItems; IObjectArray *Items; // @pyparm str|Category||Display name of the category, can also be a dll and resource id for localization // @pyparm <o PyIObjectArray>|Items||Collection of IShellItem and/or IShellLink interfaces if ( !PyArg_ParseTuple(args, "OO:AppendCategory", &obCategory, &obItems)) return NULL; if (!PyWinObject_AsWCHAR(obCategory, &Category, FALSE)) return NULL; if (!PyCom_InterfaceFromPyInstanceOrObject(obItems, IID_IObjectArray, (void **)&Items, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pICDL->AppendCategory(Category, Items); Items->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pICDL, IID_ICustomDestinationList ); Py_INCREF(Py_None); return Py_None; }
// @pymethod |PyIQueryAssociations|Init|Initializes the IQueryAssociations interface and sets the root key to the appropriate ProgID. PyObject *PyIQueryAssociations::Init(PyObject *self, PyObject *args) { IQueryAssociations *pIQA = GetI(self); if ( pIQA == NULL ) return NULL; // @pyparm int|flags||One of shellcon.ASSOCF_* flags // @pyparm string|assoc||The string data (ie, extension, prog-id, etc) // @pyparm <o PyHKEY>|hkeyProgId|None|Root registry key, can be None // @pyparm <o PyHANDLE>|hwnd|None|Reserved, must be 0 or None int flags; HWND hwnd; HKEY hkProgid; PyObject *obAssoc, *obhwnd=Py_None, *obhkProgid=Py_None; WCHAR *pszAssoc = NULL; if (!PyArg_ParseTuple(args, "lO|OO:Init", &flags, &obAssoc, &obhkProgid, &obhwnd)) return NULL; if (!PyWinObject_AsWCHAR(obAssoc, &pszAssoc, TRUE)) return NULL; if (!PyWinObject_AsHKEY(obhkProgid, &hkProgid)) return NULL; if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIQA->Init( flags, pszAssoc, hkProgid, hwnd); PyWinObject_FreeWCHAR(pszAssoc); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIQA, IID_IQueryAssociations ); Py_INCREF(Py_None); return Py_None; }
// @pymethod int|PyIQueryAssociations|GetKey|Searches for and retrieves a file association-related key from the registry. PyObject *PyIQueryAssociations::GetKey(PyObject *self, PyObject *args) { IQueryAssociations *pIQA = GetI(self); if ( pIQA == NULL ) return NULL; // @pyparm int|flags||Used to control the search. // @pyparm int|assocKey||Specifies the type of key that is to be returned. // @pyparm string||extra|Optional string with information about the location of the key. // It is normally set to a shell verb such as 'open'. Set this parameter to None if it is not used. int flags, assoc; PyObject *obExtra = Py_None; HKEY ret = NULL; WCHAR *pszExtra= NULL; if (!PyArg_ParseTuple(args, "ii|O:GetKey", &flags, &assoc, &obExtra)) return NULL; if (!PyWinObject_AsWCHAR(obExtra, &pszExtra, TRUE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIQA->GetKey( flags, (ASSOCKEY)assoc, pszExtra, &ret); PyWinObject_FreeWCHAR(pszExtra); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIQA, IID_IQueryAssociations ); // observation of the "open handles" count in task-manager indicates // this key needs to be closed! return PyWinObject_FromHKEY(ret); }
// @pymethod <o PyIID>|pythoncom|PropStgNameToFmtId|Converts a property set name to its format id (GUID) PyObject *pythoncom_PropStgNameToFmtId(PyObject *self, PyObject *args) { // @pyparm string/unicode|Name||Storage stream name FMTID fmtid; WCHAR *oszName=NULL; HRESULT err; PyObject *obName=NULL; typedef HRESULT (WINAPI * PFNPropStgNameToFmtId)(const LPOLESTR, FMTID*); static PFNPropStgNameToFmtId pfnPropStgNameToFmtId=NULL; static BOOL pfnchecked=FALSE; if (!pfnchecked){ if (ole32==NULL) ole32=GetModuleHandle(_T("Ole32.dll")); if (ole32!=NULL) pfnPropStgNameToFmtId = (PFNPropStgNameToFmtId)GetProcAddress(ole32, "PropStgNameToFmtId"); pfnchecked=TRUE; } if (pfnPropStgNameToFmtId==NULL) return PyErr_Format(PyExc_NotImplementedError,"PropStgNameToFmtId is not available on this platform"); if (!PyArg_ParseTuple(args, "O:PropStgNameToFmtId", &obName)) return NULL; if (!PyWinObject_AsWCHAR(obName,&oszName)) return NULL; PY_INTERFACE_PRECALL; err = (*pfnPropStgNameToFmtId)(oszName, &fmtid); PY_INTERFACE_POSTCALL; PyWinObject_FreeWCHAR(oszName); if (err!=S_OK) return PyCom_BuildPyException(err); return PyWinObject_FromIID(fmtid); }
// @pymethod |PyIActiveScriptDebug|GetScriptletTextAttributes|Description of GetScriptletTextAttributes. PyObject *PyIActiveScriptDebug::GetScriptletTextAttributes(PyObject *self, PyObject *args) { PY_INTERFACE_METHOD; IActiveScriptDebug *pIASD = GetI(self); if ( pIASD == NULL ) return NULL; // @pyparm string|pstrCode||The script block text. // @pyparm string|pstrDelimiter||See <om PyIActiveScriptParse::ParseScriptText> for a description of this argument. // @pyparm int|dwFlags||See <om PyIActiveScriptParse::ParseScriptText> for a description of this argument. DWORD dwFlags; PyObject *obCode, *obDelim; if ( !PyArg_ParseTuple(args, "OOi:GetScriptletTextAttributes", &obCode, &obDelim, &dwFlags) ) return NULL; BOOL bPythonIsHappy = TRUE; WCHAR *pstrDelimiter; BSTR bstr; if (!PyWinObject_AsWCHAR(obDelim, &pstrDelimiter)) bPythonIsHappy = FALSE; if (!PyCom_BstrFromPyObject(obCode, &bstr)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; ULONG uNumCodeChars = SysStringLen(bstr); SOURCE_TEXT_ATTR *pattr = new SOURCE_TEXT_ATTR[uNumCodeChars]; PY_INTERFACE_PRECALL; HRESULT hr = pIASD->GetScriptletTextAttributes( bstr, uNumCodeChars, pstrDelimiter, dwFlags, pattr ); PY_INTERFACE_POSTCALL; SysFreeString(bstr); PyWinObject_FreeWCHAR(pstrDelimiter); if ( FAILED(hr) ) return SetPythonCOMError(self,hr); return PyAXDebug_PyObject_FromSOURCE_TEXT_ATTR(pattr, uNumCodeChars); }
// @pymethod |PyIPropertySystem|UnregisterPropertySchema|Removes a set of registered properties PyObject *PyIPropertySystem::UnregisterPropertySchema(PyObject *self, PyObject *args) { IPropertySystem *pIPS = GetI(self); if ( pIPS == NULL ) return NULL; WCHAR *path; PyObject *obpath; // @pyparm str|Path||Path to a property schema XML file (.propdesc) if ( !PyArg_ParseTuple(args, "O:UnregisterPropertySchema", &obpath)) return NULL; if (!PyWinObject_AsWCHAR(obpath, &path, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIPS->UnregisterPropertySchema(path); PY_INTERFACE_POSTCALL; PyWinObject_FreeWCHAR(path); if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPS, IID_IPropertySystem ); Py_INCREF(Py_None); return Py_None; }
// @pymethod <o PyIPropertyDescriptionList>|PyIPropertySystem|GetPropertyDescriptionListFromString|Retrieves property descriptions from a string of property names PyObject *PyIPropertySystem::GetPropertyDescriptionListFromString(PyObject *self, PyObject *args) { IPropertySystem *pIPS = GetI(self); if ( pIPS == NULL ) return NULL; WCHAR *proplist; PyObject *obproplist; void *ret; IID riid = IID_IPropertyDescriptionList; // @pyparm str|PropList||String containing a list of properties and flags // @pyparm <o PyIID>|riid|IPropertyDescriptionList|The interface to return if ( !PyArg_ParseTuple(args, "O|O&:GetPropertyDescriptionListFromString", &obproplist, PyWinObject_AsIID, &riid)) return NULL; if (!PyWinObject_AsWCHAR(obproplist, &proplist, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIPS->GetPropertyDescriptionListFromString(proplist, riid, &ret); PY_INTERFACE_POSTCALL; PyWinObject_FreeWCHAR(proplist); if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPS, IID_IPropertySystem ); return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid); }
// @pymethod |PyIDocHostUIHandler|TranslateUrl|Description of TranslateUrl. PyObject *PyIDocHostUIHandler::TranslateUrl(PyObject *self, PyObject *args) { IDocHostUIHandler *pIDHUIH = GetI(self); if ( pIDHUIH == NULL ) return NULL; // @pyparm int|dwTranslate||Description for dwTranslate // @pyparm <o unicode>|pchURLIn||Description for pchURLIn PyObject *obpchURLIn; DWORD dwTranslate; OLECHAR *pchURLIn; OLECHAR *pchURLOut = 0; if ( !PyArg_ParseTuple(args, "lO:TranslateUrl", &dwTranslate, &obpchURLIn) ) return NULL; if (!PyWinObject_AsWCHAR(obpchURLIn, &pchURLIn)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIDHUIH->TranslateUrl( dwTranslate, pchURLIn, &pchURLOut); PyWinObject_FreeWCHAR(pchURLIn); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIDHUIH, IID_IDocHostUIHandler ); PyObject *pyretval = MakeOLECHARToObj(pchURLOut); CoTaskMemFree(pchURLOut); return pyretval; }
// @pymethod <o PyPROPVARIANT>|propsys|PSGetNamedPropertyFromPropertyStorage|Extracts a property value from a serialized buffer by name static PyObject *PyPSGetNamedPropertyFromPropertyStorage(PyObject *self, PyObject *args) { TmpWCHAR name; void *buf; DWORD bufsize; PROPVARIANT val; PyObject *obname, *obbuf; // @pyparm buffer|ps||Bytes or buffer (or str in python 2) containing a serialized property set (see <om PyIPersistSerializedPropStorage.GetPropertyStorage>) // @pyparm str|name||Property to return if (!PyArg_ParseTuple(args, "OO:PSGetNamedPropertyFromPropertyStorage", &obbuf, &obname)) return NULL; if (!PyWinObject_AsReadBuffer(obbuf, &buf, &bufsize, FALSE)) return NULL; if (!PyWinObject_AsWCHAR(obname, &name, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = PSGetNamedPropertyFromPropertyStorage((PCUSERIALIZEDPROPSTORAGE)buf, bufsize, name, &val); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); return PyWinObject_FromPROPVARIANT(val); }
// @pymethod |PyIFileOperation|RenameItems|Adds multiple renames to the operation sequence PyObject *PyIFileOperation::RenameItems(PyObject *self, PyObject *args) { IFileOperation *pIFO = GetI(self); if ( pIFO == NULL ) return NULL; // @pyparm <o PyIUnknown>|pUnkItems||<o PyIShellItemArray>, <o PyIDataObject>, or <o PyIEnumShellItems> containing items to be renamed // @pyparm str|NewName||New name for all items. Collisions handled automatically. PyObject *obItems; PyObject *obNewName; IUnknown * pItems; TmpWCHAR NewName; if (!PyArg_ParseTuple(args, "OO:RenameItems", &obItems, &obNewName)) return NULL; if (!PyWinObject_AsWCHAR(obNewName, &NewName, FALSE)) return NULL; if (!PyCom_InterfaceFromPyInstanceOrObject(obItems, IID_IUnknown, (void **)&pItems, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIFO->RenameItems(pItems, NewName); pItems->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIFO, IID_IFileOperation ); Py_INCREF(Py_None); return Py_None; }
// @pymethod |PyIPropertyBag|Write|Called by the control to write each property in turn to the storage provided by the container. PyObject *PyIPropertyBag::Write(PyObject *self, PyObject *args) { PyObject *obName; PyObject *obValue; // @pyparm str|propName||Name of the property to read. // @pyparm object|value||The value for the property. The value must be able to be converted to a COM VARIANT. if ( !PyArg_ParseTuple(args, "OO:Write", &obName, &obValue) ) return NULL; IPropertyBag *pIPB = GetI(self); if ( pIPB == NULL ) return NULL; TmpWCHAR Name; if ( !PyWinObject_AsWCHAR(obName, &Name)) return NULL; VARIANT var; if ( !PyCom_VariantFromPyObject(obValue, &var) ) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pIPB->Write(Name, &var); VariantClear(&var); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPB, IID_IPropertyBag); Py_INCREF(Py_None); return Py_None; }
// @pymethod <o PyIShellItem>|PyIShellLibrary|SaveInKnownFolder|Saves the library in a known folder PyObject *PyIShellLibrary::SaveInKnownFolder(PyObject *self, PyObject *args) { IShellLibrary *pISL = GetI(self); if ( pISL == NULL ) return NULL; KNOWNFOLDERID FolderToSaveIn; TmpWCHAR LibraryName; PyObject *obLibraryName; LIBRARYSAVEFLAGS Flags; IShellItem *SavedTo; // @pyparm <o PyIID>|FolderToSaveIn||The destination folder, shell.FOLDERID_* // @pyparm str|LibraryName||Filename for the new library, without file extension // @pyparm int|Flags||Determines behaviour if file already exists, shellcon.LSF_* if (!PyArg_ParseTuple(args, "O&Oi:SaveInKnownFolder", PyWinObject_AsIID, &FolderToSaveIn, &obLibraryName, &Flags)) return NULL; if (!PyWinObject_AsWCHAR(obLibraryName, &LibraryName, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISL->SaveInKnownFolder(FolderToSaveIn, LibraryName, Flags, &SavedTo); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISL, IID_IShellLibrary ); return PyCom_PyObjectFromIUnknown(SavedTo, IID_IShellItem, FALSE); }
// @pymethod <o PyIShellItem>|PyIShellLibrary|Save|Saves the library to a specific location // @rdesc Returns a shell item for the saved file. PyObject *PyIShellLibrary::Save(PyObject *self, PyObject *args) { IShellLibrary *pISL = GetI(self); if ( pISL == NULL ) return NULL; IShellItem *FolderToSaveIn, *SavedTo; PyObject *obFolderToSaveIn; TmpWCHAR LibraryName; PyObject *obLibraryName; LIBRARYSAVEFLAGS Flags; // @pyparm <o PyIShellItem>|FolderToSaveIn||The destination folder, use None to save in current user's Libraries folder // @pyparm str|LibraryName||Filename for the new library, without file extension // @pyparm int|Flags||Determines behaviour if file already exists, shellcon.LSF_* if ( !PyArg_ParseTuple(args, "OOi:Save", &obFolderToSaveIn, &obLibraryName, &Flags)) return NULL; if (!PyWinObject_AsWCHAR(obLibraryName, &LibraryName, FALSE)) return NULL; if (!PyCom_InterfaceFromPyObject(obFolderToSaveIn, IID_IShellItem, (void **)&FolderToSaveIn, TRUE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISL->Save(FolderToSaveIn, LibraryName, Flags, &SavedTo); if (FolderToSaveIn) FolderToSaveIn->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISL, IID_IShellLibrary ); return PyCom_PyObjectFromIUnknown(SavedTo, IID_IShellItem, FALSE); }
int PyDSOP_SCOPE_INIT_INFO::setattro(PyObject *self, PyObject *obname, PyObject *val) { PyDSOP_SCOPE_INIT_INFO *p = (PyDSOP_SCOPE_INIT_INFO *)self; DSOP_SCOPE_INIT_INFO *pssi = p->owner->pScopes + p->index; char *name=PyString_AsString(obname); PyErr_Clear(); if (strcmp(name, "type")==0) { pssi->flType = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "scope")==0) { pssi->flScope = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "scope")==0) { pssi->hr = PyInt_AsLong(val); if (PyErr_Occurred()) return -1; } else if (strcmp(name, "dcName")==0) { WCHAR *buf; if (!PyWinObject_AsWCHAR(val, &buf, TRUE)) return -1; PyWinObject_FreeWCHAR((WCHAR *)pssi->pwzDcName); pssi->pwzDcName = buf; } else if (strcmp(name, "filterFlags")==0) { PyErr_SetString(PyExc_AttributeError, "filterFlags attribute can not be set (try setting attributes on the object itself)"); return -1; } else { return PyObject_GenericSetAttr(self, obname, val); } return 0; }
// Helpers for passing arrays of Unicode around. BOOL PyADSI_MakeNames(PyObject *obNames, WCHAR ***names, DWORD *pcnames) { if (!PySequence_Check(obNames)) { PyErr_SetString(PyExc_TypeError, "names must be a sequence of strings"); return FALSE; } *names = NULL; int cnames = PySequence_Length(obNames); WCHAR **buf = (WCHAR **)malloc(cnames * sizeof(WCHAR *)); if (buf==NULL) { PyErr_NoMemory(); return FALSE; } memset(buf, 0, cnames * sizeof(WCHAR *)); int i=0; for (i=0;i<cnames;i++) { PyObject *ob = PySequence_GetItem(obNames, i); if (ob==NULL) goto done; BOOL ok = PyWinObject_AsWCHAR(ob, &buf[i], FALSE); Py_DECREF(ob); if (!ok) goto done; } *names = buf; *pcnames = cnames; done: if (*names==NULL) { PyADSI_FreeNames(buf, cnames); } return (*names != NULL); }
// @pymethod |PyIShellIconOverlayManager|GetReservedOverlayInfo|Description of GetReservedOverlayInfo. PyObject *PyIShellIconOverlayManager::GetReservedOverlayInfo(PyObject *self, PyObject *args) { IShellIconOverlayManager *pISIOM = GetI(self); if ( pISIOM == NULL ) return NULL; // @pyparm str|path||Description for path // @pyparm int|attrib||Description for attrib // @pyparm int|flags||Description for flags // @pyparm int|ireservedID||Description for ireservedID PyObject *obpath; TmpWCHAR path; DWORD attrib; int index; DWORD flags; int ireservedID; if ( !PyArg_ParseTuple(args, "Olli:GetReservedOverlayInfo", &obpath, &attrib, &flags, &ireservedID) ) return NULL; if (!PyWinObject_AsWCHAR(obpath, &path)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISIOM->GetReservedOverlayInfo( path, attrib, &index, flags, ireservedID ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISIOM, IID_IShellIconOverlayManager ); return PyInt_FromLong(index); }
// @pymethod int|PyIActiveScriptSite|GetItemInfo| PyObject *PyIActiveScriptSite::GetItemInfo(PyObject *self, PyObject *args) { PY_INTERFACE_METHOD; PyObject *obName; int mask; IActiveScriptSite *pMySite = GetI(self); if (pMySite==NULL) return NULL; if (!PyArg_ParseTuple(args, "Oi:GetItemInfo", &obName, &mask)) return NULL; OLECHAR *name; if (!PyWinObject_AsWCHAR(obName, &name)) return NULL; IUnknown *punk = NULL; ITypeInfo *ptype = NULL; PY_INTERFACE_PRECALL; SCODE sc = pMySite->GetItemInfo(name, mask, &punk, &ptype); PY_INTERFACE_POSTCALL; PyWinObject_FreeWCHAR(name); if (FAILED(sc)) return SetPythonCOMError(self, sc); PyObject *obDispatch = PyCom_PyObjectFromIUnknown(punk, IID_IUnknown); PyObject *obType = PyCom_PyObjectFromIUnknown(ptype, IID_ITypeInfo); PyObject *rc = NULL; if (obDispatch && obType) rc = Py_BuildValue("OO", obDispatch, obType); Py_XDECREF(obDispatch); Py_XDECREF(obType); return rc; }
BOOL PyADSIObject_AsTypedValue(PyObject *val, ADSVALUE &v) { BOOL ok = TRUE; switch (v.dwType) { // OK - get lazy - we know its a union! case ADSTYPE_DN_STRING: case ADSTYPE_CASE_EXACT_STRING: case ADSTYPE_CASE_IGNORE_STRING: case ADSTYPE_PRINTABLE_STRING: case ADSTYPE_NUMERIC_STRING: case ADSTYPE_OBJECT_CLASS: ok = PyWinObject_AsWCHAR(val, &v.DNString, FALSE); break; case ADSTYPE_BOOLEAN: v.Boolean = PyInt_AsLong(val); break; case ADSTYPE_INTEGER: v.Integer = PyInt_AsLong(val); break; case ADSTYPE_UTC_TIME: ok = PyWinObject_AsSYSTEMTIME(val, &v.UTCTime); break; case ADSTYPE_LARGE_INTEGER: ok = PyWinObject_AsLARGE_INTEGER(val, &v.LargeInteger); break; default: PyErr_SetString(PyExc_TypeError, "Cant convert to this type"); return FALSE; } return ok; }
// @pymethod <o PyIPropertyDescription>|PyIPropertySystem|GetPropertyDescriptionByName|Returns an interface used to describe a property PyObject *PyIPropertySystem::GetPropertyDescriptionByName(PyObject *self, PyObject *args) { IPropertySystem *pIPS = GetI(self); if ( pIPS == NULL ) return NULL; PyObject *obcanonicalname; WCHAR *canonicalname; IID riid = IID_IPropertyDescription; void *ret; // @pyparm str|CanonicalName||Registered name of the property // @pyparm <o PyIID>|riid|IID_IPropertyDescription|The interface to return if ( !PyArg_ParseTuple(args, "O|O&:GetPropertyDescriptionByName", &obcanonicalname, PyWinObject_AsIID, &riid)) return NULL; if (!PyWinObject_AsWCHAR(obcanonicalname, &canonicalname, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIPS->GetPropertyDescriptionByName(canonicalname, riid, &ret); PY_INTERFACE_POSTCALL; PyWinObject_FreeWCHAR(canonicalname); if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPS, IID_IPropertySystem ); return PyCom_PyObjectFromIUnknown((IUnknown *)ret, riid); }
// @object PROPSPEC|Identifies a property. Can be either an int property id, or a str/unicode property name. BOOL PyWinObject_AsPROPSPECs( PyObject *ob, PROPSPEC **ppRet, ULONG *pcRet) { TmpPyObject tuple=PyWinSequence_Tuple(ob, pcRet); if (tuple==NULL) return FALSE; size_t numBytes = sizeof(PROPSPEC) * *pcRet; *ppRet = (PROPSPEC *)malloc(numBytes); if (*ppRet==NULL) { PyErr_NoMemory(); return FALSE; } ZeroMemory(*ppRet, numBytes); for (DWORD i=0; i<*pcRet; i++) { PyObject *sub = PyTuple_GET_ITEM((PyObject *)tuple, i); (*ppRet)[i].propid = PyInt_AsUnsignedLongMask(sub); if ((*ppRet)[i].propid != (ULONG)-1 || !PyErr_Occurred()) (*ppRet)[i].ulKind = PRSPEC_PROPID; else{ PyErr_Clear(); (*ppRet)[i].lpwstr = NULL; if (PyWinObject_AsWCHAR(sub, &(*ppRet)[i].lpwstr)) (*ppRet)[i].ulKind = PRSPEC_LPWSTR; else{ PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "PROPSPECs must be a sequence of strings or integers"); PyObject_FreePROPSPECs(*ppRet, *pcRet); *ppRet=NULL; return FALSE; } } } return TRUE; }
// @pymethod int|PyIShellIconOverlayManager|GetFileOverlayInfo|Returns an index into the system image list for the icon image or overlay image PyObject *PyIShellIconOverlayManager::GetFileOverlayInfo(PyObject *self, PyObject *args) { IShellIconOverlayManager *pISIOM = GetI(self); if ( pISIOM == NULL ) return NULL; // @pyparm str|path||Full path to the file // @pyparm int|attrib||File attributes (win32com.FILE_ATTRIBUTE_*) // @pyparm int|flags||SIOM_OVERLAYINDEX (1) or SIOM_ICONINDEX (2) PyObject *obpath; TmpWCHAR path; DWORD attrib; int index; DWORD flags; if ( !PyArg_ParseTuple(args, "Oll:GetFileOverlayInfo", &obpath, &attrib, &flags) ) return NULL; if (!PyWinObject_AsWCHAR(obpath, &path)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISIOM->GetFileOverlayInfo( path, attrib, &index, flags ); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pISIOM, IID_IShellIconOverlayManager ); return PyInt_FromLong(index); }
BOOL FillADS_ATTR_INFO( ADS_ATTR_INFO *pInfo) { pInfo->dwControlCode = dwControlCode; pInfo->dwADsType = dwADsType; if (bufName == NULL) { if (!PyWinObject_AsWCHAR(obName, &bufName, FALSE)) return FALSE; } pInfo->pszAttrName = bufName; if (bufValues == NULL) { if (!PySequence_Check(obValues)) { PyErr_SetString(PyExc_TypeError, "Values attribute must be a sequence!"); return FALSE; } int n = bufValuesNum = PySequence_Length(obValues); bufValues = (ADSVALUE *)malloc(n * sizeof(ADSVALUE)); memset(bufValues, 0, n * sizeof(ADSVALUE)); if (bufValues==NULL) { PyErr_NoMemory(); return FALSE; } for (int i=0;i<n;i++) { PyObject *ob = PySequence_GetItem(obValues, i); if (ob==NULL) return FALSE; BOOL ok = PyADSIObject_AsADSVALUE(ob, bufValues[i]); Py_DECREF(ob); if (!ok) return FALSE; } } pInfo->pADsValues = bufValues; pInfo->dwNumValues = bufValuesNum; return TRUE; }
BOOL PyWinObject_AsWCHARArray(PyObject *str_seq, LPWSTR **wchars, DWORD *str_cnt, BOOL bNoneOK) { BOOL ret=FALSE; PyObject *str_tuple=NULL, *tuple_item; DWORD bufsize, tuple_index; *wchars=NULL; *str_cnt=0; if (bNoneOK && str_seq==Py_None) return TRUE; if ((str_tuple=PyWinSequence_Tuple(str_seq, str_cnt))==NULL) return FALSE; bufsize=*str_cnt * sizeof(LPWSTR); *wchars=(LPWSTR *)malloc(bufsize); if (*wchars==NULL){ PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", bufsize); goto done; } ZeroMemory(*wchars, bufsize); for (tuple_index=0;tuple_index<*str_cnt;tuple_index++){ tuple_item=PyTuple_GET_ITEM(str_tuple, tuple_index); if (!PyWinObject_AsWCHAR(tuple_item, &((*wchars)[tuple_index]), FALSE)){ PyWinObject_FreeWCHARArray(*wchars, *str_cnt); *wchars=NULL; *str_cnt=0; goto done; } } ret=TRUE; done: Py_DECREF(str_tuple); return ret; }
// @pymethod (int, <o PyIShellItem>)|PyITransferSource|RenameItem|Renames a shell item PyObject *PyITransferSource::RenameItem(PyObject *self, PyObject *args) { ITransferSource *pITS = GetI(self); if ( pITS == NULL ) return NULL; // @pyparm <o PyIShellItem>|Source||Item to be renamed // @pyparm str|NewName||The name to be given to the item TRANSFER_SOURCE_FLAGS flags; // @pyparm int|flags||Combination of shellcon.TSF_* flags PyObject *obpsiSource; PyObject *obNewName; IShellItem * psiSource; TmpWCHAR NewName; IShellItem * ppsiNewDest; if ( !PyArg_ParseTuple(args, "OOi:RenameItem", &obpsiSource, &obNewName, &flags) ) return NULL; if (!PyWinObject_AsWCHAR(obNewName, &NewName, FALSE)) return NULL; if (!PyCom_InterfaceFromPyInstanceOrObject(obpsiSource, IID_IShellItem, (void **)&psiSource, FALSE)) return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pITS->RenameItem( psiSource, NewName, flags, &ppsiNewDest ); psiSource->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pITS, IID_ITransferSource ); return Py_BuildValue("lN", hr, PyCom_PyObjectFromIUnknown(ppsiNewDest, IID_IShellItem, FALSE)); }