Ejemplo n.º 1
0
// @pymethod string|propsys|PSGetNameFromPropertyKey|Retrieves the canonical name of a property
PyObject *PyPSGetNameFromPropertyKey(PyObject *self, PyObject *args)
{
	PROPERTYKEY key;
	WCHAR *name=NULL;
	// @pyparm <o PyPROPERTYKEY>|Key||A property key
	if (!PyArg_ParseTuple(args, "O&:PSGetNameFromPropertyKey", PyWinObject_AsPROPERTYKEY, &key))
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = PSGetNameFromPropertyKey(key, &name);
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr);
	PyObject *ret = PyWinObject_FromWCHAR(name);
	CoTaskMemFree(name);
	return ret;
}
Ejemplo n.º 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;
}
Ejemplo n.º 3
0
HRESULT EnumerateProperties(PCWSTR pszFilename)
{
    IPropertyStore* pps = NULL;

    // Call the helper to get the property store for the initialized item
    // Note that as long as you have the property store, you are keeping the file open
    // So always release it once you are done.

    HRESULT hr = GetPropertyStore(pszFilename, GPS_DEFAULT, &pps);
    if (SUCCEEDED(hr))
    {
        // Retrieve the number of properties stored in the item.
        DWORD cProperties = 0;
        hr = pps->GetCount(&cProperties);
        if (SUCCEEDED(hr))
        {
            for (DWORD i = 0; i < cProperties; i++)
            {
                // Get the property key at a given index.
                PROPERTYKEY key;
                hr = pps->GetAt(i, &key);
                if (SUCCEEDED(hr))
                {
                    // Get the canonical name of the property
                    PWSTR pszCanonicalName = NULL;
                    hr = PSGetNameFromPropertyKey(key, &pszCanonicalName);
                    if (SUCCEEDED(hr))
                    {
                        hr = PrintProperty(pps, key, pszCanonicalName);
                        CoTaskMemFree(pszCanonicalName);
                    }
                }
            }
        }
        pps->Release();
    }
    else
    {
        wprintf(L"Error %x: getting the propertystore for the item.\n", hr);
    }
    return hr;
}