title: How do I use IPropertyStore to access mp3 metadata in Windows with C++?
body: <p>Given the path of an mp3 file, </p>
  
  <p><strong>how do I create and initialize an IPropertyStore object to operate on the metadata of that file?</strong></p>
  
  <p>Specifically, how do I get from here:  </p>
  
  <pre><code>"C:\\Music\\Viva Las Vegas.mp3"
  </code></pre>
  
  <p>to here:  </p>
  
  <pre><code>store-&gt;GetValue(PKEY_Music_AlbumArtist, &amp;variant);
  </code></pre>
  
  <p>Here's some pseudo-ish code to help clarify what I'm trying to do: </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;propsys.h&gt;
  #include &lt;propkey.h&gt;
  
  void main ()
  {
      // property store must somehow represent the mp3 file
      IPropertyStore* store = "C:\\Music\\Viva Las Vegas.mp3"; // HELP!
      PROPVARIANT variant;
  
      // get the existing album artist
      store-&gt;GetValue(PKEY_Music_AlbumArtist, &amp;variant);
      assert(variant== "Elvis Presley");
  
      // set it to something else
      variant= "ZZ Top";
      store-&gt;SetValue(PKEY_Music_AlbumArtist, variant);
  }
  </code></pre>
  
  <p><strong>BACKGROUND</strong></p>
  
  <p>Perhaps there is a better language for doing this but I want to use C++ (it's a long story).</p>
  
  <p>Originally, after researching mp3 metadata, it seemed like ID3 tags with TagLib was the way to go. So I wrote a utility that worked fine on a couple of fields. But then I discovered that TagLib is limited to a small subset of the many possible fields, and I want access to all of them.</p>
  
  <p>The field I'm most concerned with is Album Artist because Windows Media Player uses it as the default sort order which cannot be changed.</p>
  
  <p>I modified the TagLib source to access the Album artist instead of the Contributing artist (by changing all occurrences of '\251ART' to '\141ART') but it didn't work.</p>
  
  <p>I'm sure there is a way that everything can be done with ID3 tags but I'd rather not rely on extra stuff like TagLib, ZLIB and the CMake facility. I want to use IPropertyStore because it's built in, and it seems like the simplest way if I can just get over this hurdle.</p>
  
  <p>I found a few examples of IPropertyStore on the web, and I've tried to massage them to suit my needs without any luck, I am still mystified.</p>
  
  <p>MSDN "Help" isn't the least bit helpful -- no specs, no examples -- it doesn't even tell me which header file to include. MSDN Help is terrible now compared to what it used to be, or am I missing something? Without Google I'd be screwed. Anyway ...</p>
  
  <p>I hope someone can show me in 3 or 4 lines of code how to create and initialize IPropertyStore for my purpose. Thanks in advance.</p>