Exemple #1
0
// @pymethod (<o STATSTG>, ...)|PyIEnumSTATSTG|Next|Retrieves a specified number of items in the enumeration sequence.
PyObject *PyIEnumSTATSTG::Next(PyObject *self, PyObject *args)
{
	long celt = 1;
	// @pyparm int|num|1|Number of items to retrieve.
	if ( !PyArg_ParseTuple(args, "|l:Next", &celt) )
		return NULL;

	IEnumSTATSTG *pIESTATSTG = GetI(self);
	if ( pIESTATSTG == NULL )
		return NULL;

	STATSTG *rgVar = new STATSTG[celt];
	if ( rgVar == NULL )
		return PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", celt*sizeof(STATSTG));
	ZeroMemory(rgVar, celt*sizeof(STATSTG));

	int i;
	ULONG celtFetched;
	PyObject *result;

	PY_INTERFACE_PRECALL;
	HRESULT hr = pIESTATSTG->Next(celt, rgVar, &celtFetched);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		result=PyCom_BuildPyException(hr);
	else{
		result = PyTuple_New(celtFetched);
		if ( result != NULL ){
			for ( i = celtFetched; i--; )
			{
				PyObject *ob = PyCom_PyObjectFromSTATSTG(&rgVar[i]);
				if ( ob == NULL )
				{
					Py_DECREF(result);
					result = NULL;
					break;
				}
				PyTuple_SET_ITEM(result, i, ob);
			}
		}
	}

	for ( i = celtFetched; i--; )
		if (rgVar[i].pwcsName!=NULL)
			CoTaskMemFree(rgVar[i].pwcsName);

	delete [] rgVar;
	return result;
}
// @pymethod <o STATSTG>|PyIStorage|Stat|Retrieves the STATSTG structure for this open storage object.
PyObject *PyIStorage::Stat(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm int|grfStatFlag||Specifies that some of the fields in the STATSTG structure are not returned, thus saving a memory allocation operation. Values are taken from the STATFLAG enumeration. 
	DWORD grfStatFlag = 0;
	if ( !PyArg_ParseTuple(args, "|i:Stat", &grfStatFlag) )
		return NULL;
	STATSTG pstatstg;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->Stat( &pstatstg, grfStatFlag );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	PyObject *obpstatstg = PyCom_PyObjectFromSTATSTG(&pstatstg);
	// STATSTG doco says our responsibility to free
	if ((pstatstg).pwcsName) CoTaskMemFree((pstatstg).pwcsName);
	return obpstatstg;
}
// @pymethod <o STATSTG>|PyILockBytes|Stat|Retrieves a <o STATSTG> structure for this byte array object.
PyObject *PyILockBytes::Stat(PyObject *self, PyObject *args)
{
	ILockBytes *pILB = GetI(self);
	if ( pILB == NULL )
		return NULL;
	// @pyparm int|grfStatFlag||Specifies that this method does not return some of the fields in the STATSTG structure, thus saving a memory allocation operation. Values are taken from the STATFLAG enumerationg
	DWORD grfStatFlag;
	if ( !PyArg_ParseTuple(args, "i:Stat", &grfStatFlag) )
		return NULL;
	STATSTG pstatstg;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pILB->Stat( &pstatstg, grfStatFlag );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pILB, IID_ILockBytes);

	PyObject *obpstatstg = PyCom_PyObjectFromSTATSTG(&pstatstg);
	// STATSTG doco says our responsibility to free
	if ((pstatstg).pwcsName) CoTaskMemFree((pstatstg).pwcsName);
	PyObject *pyretval = Py_BuildValue("O", obpstatstg);
	Py_XDECREF(obpstatstg);
	return pyretval;
}