Ejemplo n.º 1
0
// @pymethod <o PyIID>|pythoncom|ReadClassStm|Retrieves the CLSID from a stream
PyObject *pythoncom_ReadClassStm(PyObject *self, PyObject *args)
{
	PyObject *obStm;
	if (!PyArg_ParseTuple(args, "O:ReadClassStm",
		&obStm))	// @pyparm <o PyIStream>|Stm||An IStream interface
		return NULL;
	IStream *pStm;
	if (!PyCom_InterfaceFromPyObject(obStm, IID_IStream, (void **)&pStm, FALSE))
		return NULL;
	CLSID clsidRet;
	PY_INTERFACE_PRECALL;
	HRESULT hr = ReadClassStm(pStm, &clsidRet);
	pStm->Release();
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return PyCom_BuildPyException(hr);
	return PyWinObject_FromIID(clsidRet);
}
Ejemplo n.º 2
0
void PropertySequence_cmd_Load (ebHTHREAD hThread, int iNumArgs, ebARGS lpArgs)
{
	BASIC_OP_TRACE(PropertySequence_cmd_Load);

	ebSetBool (lpArgs, 0, 0);		// für alle Fälle

WPropertyActionSequence ISeq ((IPropertyActionSequence *)ebGetObject (lpArgs, 1));
HRESULT hr = E_FAIL;

// Versuchen aus SubStream einzulesen
	try {
	// SubStorage eröffnen
	WStorage IStg;

		hr = GetSubPropSeqStorage (IStg.ppi());
		if (FAILED(hr)) _com_issue_error(hr);

	// Description wurde als Parameter übergeben
	string strDesc;
	ebHSUB hStr = ebGetString (lpArgs, 2);

		if (NULL != hStr) {
			strDesc = ebLockString (hThread, hStr);
			ebUnlockString (hThread, hStr);
		}
	 
	WStream IStm;
	string strName = MakeStreamName(strDesc.c_str());

	// Stream erzeugen
		USES_CONVERSION;
		hr = IStg -> OpenStream (A2OLE(strName.c_str()), NULL, 
						STGM_READ|STGM_SHARE_EXCLUSIVE, 0L, IStm.ppi());
		if (FAILED(hr)) _com_issue_error(hr);

	// ggf. XML-Version einlesen, testen nicht möglich

	// aktuelle Streamposition speichern
	LARGE_INTEGER liToPos;
	ULARGE_INTEGER liPos;

		liPos.QuadPart = liToPos.QuadPart = 0;
		if (FAILED(hr = IStm -> Seek(liToPos, STREAM_SEEK_CUR, &liPos)))
			_com_issue_error(hr);

	DWORD dwSignature = 0;
	DWORD dwVersion = 0;
	bool fMustReset = true;

		LoadData(IStm, dwSignature);
		if (dwSignature == PROPERTYSEQUENCE_SIGNATURE) {
			LoadData(IStm, dwVersion);
			if ((dwVersion & ~PROPERTYSEQUENCE_MINORVERSIONMASK) 
				<= PROPERTYSEQUENCE_LASTKNOWNVERSION)
			{
			// Versionsvergleich ist möglich (wird hier aber nicht gemacht)
			os_string strVersion;

				LoadString(IStm, strVersion);
				fMustReset = false;
			}
		}

		if (fMustReset) {
		// Stream zurückpositionieren, damit alte Streams geladen werden können
			liToPos.QuadPart = liPos.QuadPart;
			if (FAILED(hr = IStm -> Seek(liToPos, STREAM_SEEK_SET, NULL)))
				_com_issue_error(hr);
		}

	// anstelle von OleLoadFromStrem ::Load direkt rufen, da Objekt
	// schon existiert
	CLSID clsId;

		hr = ReadClassStm (IStm, &clsId);
		if (FAILED(hr)) _com_issue_error(hr);

		if (!IsEqualCLSID(clsId, CLSID_PropertyActionSequence) && 
			!IsEqualCLSID(clsId, CLSID_NULL))
		{
			_com_issue_error(E_FAIL);
		}

		{
		WPersistStream PersStm (ISeq);	// throws hr

			hr = PersStm -> Load (IStm);		// Objekt laden
			if (FAILED(hr)) _com_issue_error(hr);
		}

	} catch (...) {
		TRACE("Couldn't OleLoadFromStream for IPropertyActionSequence\n");
		return;			// Fehler
	}

	ebSetBool (lpArgs, 0, -1);
}