// @pymethod |PyIInitializeWithFile|Initialize|Passes a file path to a property handler on startup
PyObject *PyIInitializeWithFile::Initialize(PyObject *self, PyObject *args)
{
	IInitializeWithFile *pIIWF = GetI(self);
	if ( pIIWF == NULL )
		return NULL;
	TmpWCHAR path;
	PyObject *obpath;
	// @pyparm str|FilePath||Full path to the file whose properties are to be accessed
	// @pyparm int|Mode||Indicates if properties can be written, STGM_READ or STGM_READWRITE
	DWORD grfMode;
	if ( !PyArg_ParseTuple(args, "Ok:Initialize", &obpath, &grfMode) )
		return NULL;
	if (!PyWinObject_AsWCHAR(obpath, &path, FALSE))
		return NULL;

	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIIWF->Initialize(path, grfMode );
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIIWF, IID_IInitializeWithFile );
	Py_INCREF(Py_None);
	return Py_None;
}
예제 #2
0
int _tmain(int argc, _TCHAR* argv[])
{
	CLSID wid;
	CoInitialize(NULL);
	CLSIDFromString(const_cast<wchar_t*>(default_guid), &wid);
	IInitializeWithFile *oo;
	HRESULT hr;
	if ((hr = CoCreateInstance(wid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&oo))) != S_OK)
		fail();
#if 0
	IStorage *isto;
	if ((hr = StgCreateDocfile(L"t.mp3", STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT, 0, &isto)) != S_OK)
		fail();
	IStream *is;
	if ((hr = isto->CreateStream(L"lol", STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &is)) != S_OK)
		fail();
#endif
	IPropertyStore *ips;
	IPropertyStoreCapabilities *ipcs;
	if ((hr = oo->QueryInterface(IID_PPV_ARGS(&ips))) != S_OK)
		fail();

	if ((hr = oo->QueryInterface(IID_PPV_ARGS(&ipcs))) != S_OK)
		fail();

	//iws->Initialize(is, STGM_READWRITE);
	if ((hr = oo->Initialize(L"t.mp3", STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT)) != S_OK)
		fail();

	DWORD props;
	if ((hr = ips->GetCount(&props)) != S_OK)
		fail();

	for (DWORD i = 0; i < props; ++i)
	{
		PROPERTYKEY pkey;
		ips->GetAt(i, &pkey);
		WCHAR *sz;
		PSGetNameFromPropertyKey(pkey, &sz);
		std::wcout << (ipcs->IsPropertyWritable(pkey) == S_OK) << "\t" << sz << std::endl;
	}
	return 0;
}
예제 #3
0
HRESULT PreviewGenerator::ShowPreviewWithPreviewHandler(CString filePath, CLSID cls)
{
	DWORD dwRet = ERROR_BAD_ARGUMENTS;
	IInitializeWithFile		*iIFile;
	if (iPHandler)
	{
		iPHandler->Unload();
		SAFERELEASE(iPHandler);
	}
	HRESULT hr = CoCreateInstance(cls, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IPreviewHandler, (LPVOID*)&iPHandler);
	if (hr == S_OK)
	{
		hr = iPHandler->QueryInterface(IID_IInitializeWithFile, (LPVOID*)&iIFile);
	}
	else
		return hr;
	if (iIFile && hr == S_OK)
		hr = iIFile->Initialize(filePath, STGM_READ);

	if (iPHandler &&  hr == S_OK)
		hr = DoPreview();
	SAFERELEASE(iIFile);
	return hr;
}