question

Pushkins-9024 avatar image
0 Votes"
Pushkins-9024 asked RLWA32-6355 answered

PROPVARIANT

Hi

Was wondering if somebody could help me. I have the below code and everything works fine until it gets to

store->GetValue(PKEY_Music_Artist, &variant);
m_strArtistsTag = variant.pwszVal;

and then it just crashes. I'm thinking it has something to do with .pwszVal. But not sure.
All the other store->GetValue's work perfectly



void CQueriesCheckTags::GetFileTags(CString strFilePath)
{
IPropertyStore* store = NULL;
PROPVARIANT variant;

if (m_FilePath.Right(4) == _T(".mp3"))
{
// initialize the COM library
CoInitialize(NULL);

HRESULT hr = SHGetPropertyStoreFromParsingName(m_FilePath,
NULL, GPS_READWRITE, __uuidof(IPropertyStore), (void**)&store);

if (hr != S_OK)
AfxMessageBox(m_FilePath);

store->GetValue(PKEY_Music_AlbumTitle, &variant);
m_strAlbumTitleTag = variant.pwszVal;

store->GetValue(PKEY_Title, &variant);
m_strSongTitleTag = variant.pwszVal;

store->GetValue(PKEY_Music_Artist, &variant);
m_strArtistsTag = variant.pwszVal;

store->GetValue(PKEY_Music_TrackNumber, &variant);
m_strTrackTag.Format(_T("%d"), variant.intVal);

//very important undocumented method
store->Release();

CoUninitialize();

}
}

c++
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Variant.pwszVal can be used if variant.vt has the corresponding variant type. Did you check the value of variant.vt?

Also check if store->GetValue returns a success code. (You can use the SUCCEEDED macro).



0 Votes 0 ·

Hi


The Visual Studio Docs say PKEY_Music_Artist type = Multivalue String. I have m_strArtistsTag defined as a CString. I think that some how this is where I am going wrong as I'm not sure what a Multivalue string should be defined as or what I should be putting on the end of variant instead of pwszVal

Hope this makes sense.

store->GetValue returns S_OK so I can only assume that it is working correctly

Thank you

0 Votes 0 ·

What number did you obtain in variant.vt?



0 Votes 0 ·

1 Answer

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered

First, you should not re-use the same PROPVARIANT struct to receive multiple properties without calling PropVariantClear after you are done with the property retrieved from each call to IPropertyStore::GetValue.

A Multivalue String property contained in a PROPVARIANT struct can be extracted using the PropVariantToStringVector function or the PropVariantToStringVectorAlloc function


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.