PROPVARIANT

Pushkins 156 Reputation points
2021-10-30T01:17:24.627+00:00

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++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,526 questions
{count} votes

Accepted answer
  1. RLWA32 40,286 Reputation points
    2021-10-30T09:33:05.387+00:00

    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

    0 comments No comments

0 additional answers

Sort by: Most helpful