Ejemplo n.º 1
1
// @pymethod (int, ...)/int|PyIDispatch|GetIDsOfNames|Get the DISPID for the passed names.
PyObject *PyIDispatch::GetIDsOfNames(PyObject *self, PyObject *args)
{
	// @rdesc If the first parameter is a sequence, the result will be a tuple of integers
	// for each name in the sequence.  If the first parameter is a single string, the result
	// is a single integer with the ID of requested item.
	UINT i;

	// @pyparm string|name||A name to query for
	// @pyparmalt1 [string, ...]|[name, ...]||A sequence of string names to query
	// @comm Currently the LCID can not be specified, and  LOCALE_SYSTEM_DEFAULT is used.
	int argc = PyTuple_GET_SIZE(args);
	if ( argc < 1 )
		return PyErr_Format(PyExc_TypeError, "At least one argument must be supplied");

	LCID lcid = LOCALE_SYSTEM_DEFAULT;
	UINT offset = 0;
	if ( argc > 1 ){
		PyObject *ob = PyTuple_GET_ITEM(args, 0);
		lcid=PyLong_AsLong(ob);
		if (lcid==-1 && PyErr_Occurred()){
			PyErr_Clear();
			lcid=LOCALE_SYSTEM_DEFAULT;
			}
		else
			offset = 1;
		}

	UINT cNames = argc - offset;
	OLECHAR FAR* FAR* rgszNames = new LPOLESTR[cNames];

	for ( i = 0 ; i < cNames; ++i )
	{
		PyObject *ob = PySequence_GetItem(args, i + offset);
		if ( !ob )
		{
			for (;i>0;i--)
				PyWinObject_FreeBstr(rgszNames[i-1]);
			delete [] rgszNames;
			return NULL;
		}
		if (!PyWinObject_AsBstr(ob, rgszNames+i)) {
			for (;i>0;i--)
				PyWinObject_FreeBstr(rgszNames[i-1]);
			delete [] rgszNames;
			return NULL;
		}
		Py_DECREF(ob);
	}

	DISPID FAR* rgdispid = new DISPID[cNames];
	IDispatch *pMyDispatch = GetI(self);
	if (pMyDispatch==NULL) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pMyDispatch->GetIDsOfNames(IID_NULL, rgszNames, cNames, lcid, rgdispid);
	PY_INTERFACE_POSTCALL;

	for (i=0;i<cNames;i++)
		PyWinObject_FreeBstr(rgszNames[i]);
	delete [] rgszNames;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pMyDispatch, IID_IDispatch);

	PyObject *result;

	/* if we have just one name, then return a single DISPID (int) */
	if ( cNames == 1 )
	{
		result = PyInt_FromLong(rgdispid[0]);
	}
	else
	{
		result = PyTuple_New(cNames);
		if ( result )
		{
			for ( i = 0; i < cNames; ++i )
			{
				PyObject *ob = PyInt_FromLong(rgdispid[i]);
				if ( !ob )
				{
					delete [] rgdispid;
					return NULL;
				}
				PyTuple_SET_ITEM(result, i, ob);
			}
		}
	}

	delete [] rgdispid;
	return result;
}
Ejemplo n.º 2
0
// @pymethod |PyIStorage|MoveElementTo|Copies or moves a substorage or stream from this storage object to another storage object.
PyObject *PyIStorage::MoveElementTo(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|name||A string that contains the name of the element in this storage object to be moved or copied.
	// @pyparm <o PyIStorage>|stgDest||<o PyIStorage> for the destination storage object.
	// @pyparm string|newName||A string that contains the new name for the element in its new storage object.
	// @pyparm int|grfFlags||Specifies whether the operation should be a move (STGMOVE_MOVE) or a copy (STGMOVE_COPY). See the STGMOVE enumeration.
	PyObject *obName, *obNewName;
	PyObject *obpstgDest;
	DWORD grfFlags;
	if ( !PyArg_ParseTuple(args, "OOOi:MoveElementTo", &obName, &obpstgDest, &obNewName, &grfFlags) )
		return NULL;
	IStorage *pstgDest;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrName, bstrNewName;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName);
	if (!PyWinObject_AsBstr(obNewName, &bstrNewName))
		bPythonIsHappy = FALSE;
	if (!PyCom_InterfaceFromPyObject(obpstgDest, IID_IStorage, (void **)&pstgDest, FALSE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->MoveElementTo( bstrName, pstgDest, bstrNewName, grfFlags );
	pstgDest->Release();
	PY_INTERFACE_POSTCALL;
	PyWinObject_FreeBstr(bstrName);
	PyWinObject_FreeBstr(bstrNewName);
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}
Ejemplo n.º 3
0
// @pymethod |PyIStorage|RenameElement|Renames the specified substorage or stream in this storage object.
PyObject *PyIStorage::RenameElement(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|oldName||The name of the substorage or stream to be changed.
	// @pyparm string|newName||The new name for the specified sustorage or stream.
	PyObject *obNewName, *obOldName;
	if ( !PyArg_ParseTuple(args, "OO:RenameElement", &obOldName, &obNewName) )
		return NULL;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrNewName, bstrOldName;
	bPythonIsHappy = PyWinObject_AsBstr(obOldName, &bstrOldName);
	if (!PyWinObject_AsBstr(obNewName, &bstrNewName))
		bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->RenameElement( bstrOldName, bstrNewName );
	PyWinObject_FreeBstr(bstrOldName);
	PyWinObject_FreeBstr(bstrNewName);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}
Ejemplo n.º 4
0
// @pymethod |PyICreateTypeInfo|SetFuncAndParamNames|Description of SetFuncAndParamNames.
PyObject *PyICreateTypeInfo::SetFuncAndParamNames(PyObject *self, PyObject *args)
{
	ICreateTypeInfo *pICTI = GetI(self);
	if ( pICTI == NULL )
		return NULL;
	// @pyparm int|index||Index of the item to set.
	// @pyparm (<o unicode>, ...)|rgszNames||A sequence of unicode or String objects.
	PyObject *obrgszNames;
	UINT index;
	if ( !PyArg_ParseTuple(args, "iO:SetFuncAndParamNames", &index, &obrgszNames) )
		return NULL;
	BOOL bPythonIsHappy = TRUE;

	// String and Unicode will pass the "is sequence" test, so we reject these!
	BSTR bstrTemp;
	if (PyWinObject_AsBstr(obrgszNames, &bstrTemp)) {
		PyWinObject_FreeBstr(bstrTemp);
		PyErr_SetString(PyExc_TypeError, "The names param must be a sequence of strings/unicodes");
		return NULL;
	}
	PyErr_Clear(); // clear the exception set by PyWinObject_AsBstr
	if (!PySequence_Check(obrgszNames)) {
		PyErr_SetString(PyExc_TypeError, "The names param must be a sequence of strings/unicodes");
		return NULL;
	}
	UINT cNames = PySequence_Length(obrgszNames);
	OLECHAR **pNames = new OLECHAR *[cNames];
	memset(pNames, sizeof(OLECHAR *) * cNames, 0);
	UINT i;
	for (i=0;bPythonIsHappy && i<cNames;i++) {
		PyObject *item = PySequence_GetItem(obrgszNames, i);
		if (item==NULL) 
			bPythonIsHappy = FALSE;
		else
			bPythonIsHappy = PyWinObject_AsBstr(item, pNames+i);
		Py_DECREF(item);
	}
	if (!bPythonIsHappy) {
		for (i=0;i<cNames;i++)
				PyWinObject_FreeBstr(pNames[i]);
		delete pNames;
		return NULL;
	}
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pICTI->SetFuncAndParamNames( index, pNames, cNames );
	PY_INTERFACE_POSTCALL;

	for (i=0;i<cNames;i++)
			PyWinObject_FreeBstr(pNames[i]);
	delete pNames;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pICTI, IID_ICreateTypeInfo);
	Py_INCREF(Py_None);
	return Py_None;
}
Ejemplo n.º 5
0
// @pymethod <o PyIStream>|PyIStorage|OpenStream|Opens an existing stream object within this storage object in the specified access mode.
PyObject *PyIStorage::OpenStream(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|pwcsName||Description for pwcsName
	// @pyparm object|reserved1||A reserved param.  Always pass None.  NULL is always passed to the COM function
	// @pyparm int|grfMode||Specifies the access mode to be assigned to the open stream. See the STGM enumeration values for descriptions of the possible values. . Whatever other modes you may choose, you must at least specify STGM_SHARE_EXCLUSIVE when calling this method.
	// @pyparm int|reserved2|0|Reserved - must be zero.
	PyObject *obName;
	DWORD grfMode;
	PyObject *obreserved1;
	DWORD reserved2 = 0;
	if ( !PyArg_ParseTuple(args, "OOi|i:OpenStream", &obName, &obreserved1, &grfMode, &reserved2) )
		return NULL;
	if (obreserved1 != Py_None) {
		PyErr_SetString(PyExc_TypeError, "The 'reserved' parameter (param 2) must be None");
		return NULL;
	}
	IStream *ppstm;
	BOOL bPythonIsHappy = TRUE;
	BSTR name;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &name);
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->OpenStream( name, NULL, grfMode, reserved2, &ppstm );
	PyWinObject_FreeBstr(name);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppstm, IID_IStream, FALSE);
}
Ejemplo n.º 6
0
// @pymethod <o PyIStream>|PyIStorage|CreateStream|Creates and opens a stream object with the specified name contained in this storage object. All elements within a storage object — both streams and other storage objects — are kept in the same name space.
PyObject *PyIStorage::CreateStream(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|pwcsName||Name of the new stream
	// @pyparm int|grfMode||Specifies the access mode to use when opening the newly created stream.
	// @pyparm int|reserved1|0|Reserved - must be zero.
	// @pyparm int|reserved2|0|Reserved - must be zero.
	DWORD grfMode;
	DWORD reserved1 = 0;
	DWORD reserved2 = 0;
	PyObject *obName;
	if ( !PyArg_ParseTuple(args, "Oi|ii:CreateStream", &obName, &grfMode, &reserved1, &reserved2) )
		return NULL;
	IStream *ppstm;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrName;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName);
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->CreateStream( bstrName, grfMode, reserved1, reserved2, &ppstm );
	PyWinObject_FreeBstr(bstrName);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppstm, IID_IStream, FALSE);
}
Ejemplo n.º 7
0
// @pymethod <o PyIStorage>|PyIStorage|CreateStorage|Creates and opens a new storage object nested within this storage object.
PyObject *PyIStorage::CreateStorage(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|pwcsName||The name of the newly created stream.
	// @pyparm int|grfMode||Specifies the access mode to use when opening the newly created storage object.
	// @pyparm int|dwStgFmt||Documented as "reserved"!
	// @pyparm int|reserved2|0|Description for reserved2
	PyObject *obName;
	DWORD grfMode;
	DWORD dwStgFmt;
	DWORD reserved2 = 0;
	if ( !PyArg_ParseTuple(args, "Oii|i:CreateStorage", &obName, &grfMode, &dwStgFmt, &reserved2) )
		return NULL;
	IStorage *ppstg;
	BOOL bPythonIsHappy = TRUE;
	BSTR name;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &name);
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->CreateStorage( name, grfMode, dwStgFmt, reserved2, &ppstg );
	PY_INTERFACE_POSTCALL;
	PyWinObject_FreeBstr(name);
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppstg, IID_IStorage, FALSE);
}
Ejemplo n.º 8
0
/* static */ PyObject *PyIActiveScript::GetScriptDispatch(PyObject *self, PyObject *args)
{
	PY_INTERFACE_METHOD;
	PyObject *obItemName = Py_None;
	if ( !PyArg_ParseTuple(args, "|O:GetScriptDispatch", &obItemName) )
		return NULL;

	IActiveScript *pIAS = GetI(self);
	if ( pIAS == NULL )
		return NULL;

	BSTR pstrItemName = NULL;
	if (!PyWinObject_AsBstr(obItemName, &pstrItemName, TRUE))
		return NULL;

	IDispatch *pdisp;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIAS->GetScriptDispatch(pstrItemName, &pdisp);
	PY_INTERFACE_POSTCALL;
	PyWinObject_FreeBstr(pstrItemName);
	if ( FAILED(hr) )
		return SetPythonCOMError(self, hr);

	if ( !pdisp )
	{
		Py_INCREF(Py_None);
		return Py_None;
	}

	return PyCom_PyObjectFromIUnknown((IUnknown *)pdisp, IID_IDispatch, FALSE);
}
Ejemplo n.º 9
0
// @object PROPSPEC|Identifies a property.  Can be either an int property id, or a str/unicode property name.
BOOL PyObject_AsPROPSPECs( PyObject *ob, PROPSPEC **ppRet, ULONG *pcRet)
{
	BOOL ret=FALSE;
	DWORD len, i;
	PyObject *tuple=PyWinSequence_Tuple(ob, &len);
	if (tuple==NULL)
		return FALSE;

	// First count the items, and the total string space we need.
	size_t cChars = 0;
	for (i=0;i<len;i++) {
		PyObject *sub = PyTuple_GET_ITEM(tuple, i);
		if (PyUnicode_Check(sub))
			cChars += PyUnicode_GET_SIZE(sub) + 1;
		else if (PyString_Check(sub))
			cChars += PyString_Size(sub) + 1;
		else if (PyInt_Check(sub))
			;	// PROPID is a ULONG, so this may fail for values that require a python long
		else {
			PyErr_SetString(PyExc_TypeError, "PROPSPECs must be a sequence of strings or integers");
			goto cleanup;
		}
	}
	size_t numBytes;
	numBytes = (sizeof(PROPSPEC) * len) + (sizeof(WCHAR) * cChars);
	PROPSPEC *pRet;
	pRet = (PROPSPEC *)malloc(numBytes);
	if (pRet==NULL) {
		PyErr_SetString(PyExc_MemoryError, "allocating PROPSPECs");
		goto cleanup;
	}
	WCHAR *curBuf;
	curBuf = (WCHAR *)(pRet+len);
	for (i=0;i<len;i++) {
		PyObject *sub = PyTuple_GET_ITEM(tuple, i);
		BSTR bstr;
		if (PyWinObject_AsBstr(sub, &bstr)) {
			pRet[i].ulKind = PRSPEC_LPWSTR;
			pRet[i].lpwstr = curBuf;
			wcscpy( curBuf, bstr);
			curBuf += wcslen(curBuf) + 1;
			PyWinObject_FreeBstr(bstr);
		} else {
			PyErr_Clear();
			pRet[i].ulKind = PRSPEC_PROPID;
			pRet[i].propid = PyInt_AsLong(sub);
		}
	}
	ret=TRUE;
	*ppRet = pRet;
	*pcRet = len;
cleanup:
	Py_DECREF(tuple);
	return ret;
}
Ejemplo n.º 10
0
// @pymethod <o DESCKIND>|PyITypeComp|BindType|binds to a type
static PyObject *typecomp_bindtype(PyObject *self, PyObject *args)
{
	PyObject *obS;
	// @pyparm string|szName||The name to bind to
	if (!PyArg_ParseTuple(args, "O:BindType", &obS))
		return NULL;
	BSTR bstrS;
	if (!PyWinObject_AsBstr(obS, &bstrS))
		return NULL;
	PyObject *rc = ((PyITypeComp*)self)->BindType(bstrS);
	PyWinObject_FreeBstr(bstrS);
	return rc;
}
Ejemplo n.º 11
0
// @pymethod <o DESCKIND>|PyITypeComp|Bind|binds to a variable/type
static PyObject *typecomp_bind(PyObject *self, PyObject *args)
{
	PyObject *obS;
	int		w=0;
	// @pyparm string|szName||The name to bind to
	// @pyparm int|wflags|0|the bind flags
	if (!PyArg_ParseTuple(args, "O|i:Bind", &obS, &w))
		return NULL;
	BSTR bstrS;
	if (!PyWinObject_AsBstr(obS, &bstrS))
		return NULL;
	PyObject *rc = ((PyITypeComp*)self)->Bind(bstrS,w);
	PyWinObject_FreeBstr(bstrS);
	return rc;
}
Ejemplo n.º 12
0
// @pymethod |PyIStorage|SetElementTimes|Sets the modification, access, and creation times of the specified storage element, if supported by the underlying file system.
PyObject *PyIStorage::SetElementTimes(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|name||The name of the storage object element whose times are to be modified. If NULL, the time is set on the root storage rather than one of its elements. 
	// @pyparm <o PyTime>|ctime||Either the new creation time for the element or None if the creation time is not to be modified.
	// @pyparm <o PyTime>|atime||Either the new access time for the element or None if the access time is not to be modified.
	// @pyparm <o PyTime>|mtime||Either the new modification time for the element or None if the modification time is not to be modified.
	PyObject *obName;
	PyObject *obpctime;
	PyObject *obpatime;
	PyObject *obpmtime;
	if ( !PyArg_ParseTuple(args, "OOOO:SetElementTimes", &obName, &obpctime, &obpatime, &obpmtime) )
		return NULL;
	FILETIME *pctime=NULL, ctime;
	FILETIME *patime=NULL, atime;
	FILETIME *pmtime=NULL, mtime;
	if (obpctime!=Py_None) {
		if (!PyWinObject_AsFILETIME(obpctime, &ctime))
			return NULL;
		pctime = &ctime;
	}
	if (obpatime != Py_None) {
		if (!PyWinObject_AsFILETIME(obpatime, &atime))
			return NULL;
		patime = &atime;
	}
	if (obpmtime != Py_None) {
		if (!PyWinObject_AsFILETIME(obpmtime, &mtime))
			return NULL;
		pmtime = &mtime;
	}
	BSTR bstrName;
	if (!PyWinObject_AsBstr(obName, &bstrName))
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->SetElementTimes( bstrName, pctime, patime, pmtime );
	PyWinObject_FreeBstr(bstrName);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;
}
Ejemplo n.º 13
0
// @pymethod <o PyITypeLib>|pythoncom|LoadTypeLib|Loads a registered type library.
PyObject *pythoncom_loadtypelib(PyObject *self, PyObject *args)
{
	PyObject *obName;
	// @pyparm string|libFileName||The path to the file containing the type information.
	if (!PyArg_ParseTuple(args, "O:LoadTypeLib", &obName))
		return NULL;

	BSTR bstrName;
	if (!PyWinObject_AsBstr(obName, &bstrName))
		return NULL;

	ITypeLib *ptl;
	PY_INTERFACE_PRECALL;
	SCODE sc = LoadTypeLib(bstrName, &ptl);
	PyWinObject_FreeBstr(bstrName);
	PY_INTERFACE_POSTCALL;
	if (FAILED(sc))
		return PyCom_BuildPyException(sc);

	return PyCom_PyObjectFromIUnknown(ptl, IID_ITypeLib);
}
Ejemplo n.º 14
0
// @pymethod <o PyIStorage>|PyIStorage|OpenStorage|Opens an existing storage object with the specified name in the specified access mode.
PyObject *PyIStorage::OpenStorage(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|pwcsName||Name of the storage, or None.
	// @pyparm <o PyIStorage>|pstgPriority||If the pstgPriority parameter is not None, it is a <o PyIStorage> object to a previous opening of an element of the storage object, 
	// usually one that was opened in priority mode. The storage object should be closed and re-opened 
	// according to grfMode. When the <om PyIStorage.OpenStorage> method returns, pstgPriority is no longer valid - use the result value. 
	// If the pstgPriority parameter is None, it is ignored.
	// @pyparm int|grfMode||Specifies the access mode to use when opening the storage object. See the STGM enumeration values for descriptions of the possible values. Whatever other modes you may choose, you must at least specify STGM_SHARE_EXCLUSIVE when calling this method. 
	// @pyparm <o SNB>|snbExclude||Reserved for later - Must be None
	// @pyparm int|reserved|0|Reserved integer param.
	PyObject *obName;
	PyObject *obpstgPriority;
	DWORD grfMode;
	DWORD reserved = 0;
	char *temp = NULL;
	if ( !PyArg_ParseTuple(args, "OOi|zi:OpenStorage", &obName, &obpstgPriority, &grfMode, &temp, &reserved) )
		return NULL;
	IStorage *pstgPriority;
	IStorage *ppstg;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrName;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName, TRUE);
	if (!PyCom_InterfaceFromPyObject(obpstgPriority, IID_IStorage, (void **)&pstgPriority, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->OpenStorage( bstrName, pstgPriority, grfMode, NULL, reserved, &ppstg );
	if ( pstgPriority != NULL )
		pstgPriority->Release();
	PyWinObject_FreeBstr(bstrName);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppstg, IID_IStorage, FALSE);
}
Ejemplo n.º 15
0
// @pymethod |PyIStorage|DestroyElement|Removes the specified storage or stream from this storage object.
PyObject *PyIStorage::DestroyElement(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|name||The name of the element to be removed.
	PyObject *obName;
	if ( !PyArg_ParseTuple(args, "O:DestroyElement", &obName) )
		return NULL;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrName;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName);
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->DestroyElement( bstrName );
	PY_INTERFACE_POSTCALL;
	PyWinObject_FreeBstr(bstrName);
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}
Ejemplo n.º 16
0
// @pymethod int|PyITypeInfo|GetIDsOfNames|Maps between member names and member IDs, and parameter names and parameter IDs.
static PyObject *typeinfo_getidsofnames(PyObject *self, PyObject *args)
{
	// XXX - todo - merge this code with PyIDispatch::GetIDsOfNames
	ITypeInfo *pti = PyITypeInfo::GetI(self);
	if (pti==NULL) return NULL;
	UINT i;
	int argc = PyTuple_GET_SIZE(args);
	if ( argc < 1 ) {
		PyErr_SetString(PyExc_TypeError, "At least one argument must be supplied");
		return NULL;
	}
	LCID lcid = LOCALE_SYSTEM_DEFAULT;
	UINT offset = 0;
	if ( argc > 1 )
	{
		PyObject *ob = PyTuple_GET_ITEM(args, 0);
		lcid=PyLong_AsLong(ob);
		if (lcid==-1 && PyErr_Occurred()){
			PyErr_Clear();
			lcid=LOCALE_SYSTEM_DEFAULT;
			}
		else
			offset = 1;
	}

	UINT cNames = argc - offset;
	OLECHAR FAR* FAR* rgszNames = new LPOLESTR[cNames];

	for ( i = 0 ; i < cNames; ++i )
	{
		PyObject *ob = PyTuple_GET_ITEM(args, i + offset);
		if (!PyWinObject_AsBstr(ob, rgszNames+i)) {
			for (;i>0;i--)
				PyWinObject_FreeBstr(rgszNames[i-1]);
			delete [] rgszNames;
			return NULL;
		}
	}

	DISPID FAR* rgdispid = new DISPID[cNames];
	PY_INTERFACE_PRECALL;
	HRESULT hr = pti->GetIDsOfNames(rgszNames, cNames, rgdispid);
	PY_INTERFACE_POSTCALL;

	for (i=0;i<cNames;i++)
		PyWinObject_FreeBstr(rgszNames[i]);
	delete [] rgszNames;

	if ( FAILED(hr) ){
		delete [] rgdispid;
		return PyCom_BuildPyException(hr, pti, IID_ITypeInfo);
		}
	PyObject *result;

	/* if we have just one name, then return a single DISPID (int) */
	if ( cNames == 1 )
	{
		result = PyInt_FromLong(rgdispid[0]);
	}
	else
	{
		result = PyTuple_New(cNames);
		if ( result )
		{
			for ( i = 0; i < cNames; ++i )
			{
				PyObject *ob = PyInt_FromLong(rgdispid[i]);
				if ( !ob )
				{
					delete [] rgdispid;
					return NULL;
				}
				PyTuple_SET_ITEM(result, i, ob);
			}
		}
	}

	delete [] rgdispid;
	return result;
}
Ejemplo n.º 17
0
// @object PyMAPINAMEIDArray|A sequence (<o PyIID>, string/int) objects
BOOL PyMAPIObject_AsMAPINAMEIDArray(PyObject *ob, MAPINAMEID ***pppNameId, ULONG *pNumIds, BOOL bNoneOK /*= FALSE*/ )
{
    if (bNoneOK && ob==Py_None) {
        *pppNameId = NULL;
        *pNumIds = 0;
        return TRUE;
    }
    PyErr_Clear();
    ULONG len = (ULONG)PySequence_Length(ob);
    if (PyErr_Occurred()) {
        PyErr_Clear();
        PyErr_SetString(PyExc_TypeError, "MAPINAMEID array list be a sequence of tuples");
        return FALSE;
    }
    MAPINAMEID **ppNew = NULL;
    MAPINAMEID *prgIds = NULL;
    IID *pIIDs = NULL;
    HRESULT hr = MAPIAllocateBuffer(len * sizeof(MAPINAMEID *), (void **)&ppNew);
    if (SUCCEEDED(hr)) hr = MAPIAllocateMore(len * sizeof(MAPINAMEID), ppNew, (void **)&prgIds);
    if (SUCCEEDED(hr)) hr = MAPIAllocateMore(len * sizeof(IID), ppNew, (void **)&pIIDs);
    if (FAILED(hr)) {
        MAPIFreeBuffer(ppNew);
        OleSetOleError(hr);
        return FALSE;
    }
    for (ULONG i=0; i<len; i++) {
        ppNew[i] = prgIds+i;
        MAPINAMEID *pNew = prgIds+i;
        PyObject *obIID, *obPropId;
        PyObject *pMe = PySequence_GetItem(ob, i);
        if (pMe==NULL) {
            goto loop_error;
        }
        if (!PyArg_ParseTuple(pMe, "OO", &obIID, &obPropId )) {
            PyErr_Clear();
            PyErr_SetString(PyExc_TypeError, "MAPINAMEIDArray must be a sequence of (iid, string/int) tuples");
            goto loop_error;
        }

        pNew->lpguid = pIIDs+i;
        BSTR bstrVal;
        if (!PyWinObject_AsIID(obIID, pIIDs+i))
            goto loop_error;
        if (PyInt_Check(obPropId)) {
            pNew->ulKind = MNID_ID;
            pNew->Kind.lID = PyInt_AsLong(obPropId);
        } else if (PyWinObject_AsBstr(obPropId, &bstrVal)) {
            // Make a copy of the string
            pNew->ulKind = MNID_STRING;
            DWORD strLen = SysStringLen(bstrVal);
            hr = MAPIAllocateMore(sizeof(WCHAR) * (strLen+1), ppNew, (void **)&pNew->Kind.lpwstrName);
            if (FAILED(hr)) {
                PyWinObject_FreeBstr(bstrVal);
                OleSetOleError(hr);
                goto loop_error;
            }
            wcsncpy(pNew->Kind.lpwstrName, bstrVal, strLen+1);
            PyWinObject_FreeBstr(bstrVal);
        } else {
            PyErr_SetString(PyExc_TypeError, "The type of property ID is invalid - must be string/unicode or int");
            goto loop_error;
        }
        Py_DECREF(pMe);
        continue;
loop_error:
        Py_XDECREF(pMe);
        MAPIFreeBuffer(ppNew);
        return NULL;
    }
    *pppNameId = ppNew;
    *pNumIds = len;
    return TRUE;
}