title: Cereal serialize CString Vector
body: <p>EDIT:// Got it working thanks to the answer below, adding the code that is currently working and test case just in case some one might find it useful.</p>
  
  <pre><code>// Add as another type for Cereal or inside string.hpp in Cereal includes      
    template&lt;class Archive&gt; inline
        void CEREAL_SAVE_FUNCTION_NAME(Archive &amp; ar, CString str)
    {
        // Save number of chars + the data
        size_type size = (str.GetLength() + 1) * sizeof(TCHAR);
        ar(size);
        ar(binary_data(str.GetBuffer(), static_cast&lt;std::size_t&gt;(size)));
        str.ReleaseBuffer();
    }
  
    template&lt;class Archive&gt; inline
        void CEREAL_LOAD_FUNCTION_NAME(Archive &amp; ar, CString &amp; str)
    {
        size_type size;
        ar(size);
        ar(binary_data(str.GetBuffer(static_cast&lt;std::size_t&gt;(size)), static_cast&lt;std::size_t&gt;(size)));
        str.ReleaseBuffer();
    }
  </code></pre>
  
  <p>Below is the code I used to test, it correctly outputs all the elements of the vector.</p>
  
  <pre><code>class Stuff
  {
  public:
      Stuff() {}
      std::vector&lt;CString&gt; vec;
  private:
      friend class cereal::access;
      template &lt;class Archive&gt;
      void serialize(Archive &amp; ar)
      {
          ar(vec);
      }
  };
  
  int main()
  {
      Stuff myStuff, otherStuff;
  
      myStuff.vec.push_back(L"Testing different length CStrings");
      myStuff.vec.push_back(L"Separator");
      myStuff.vec.push_back(L"Is it working yet??");
      myStuff.vec.push_back(L"1234567890");
      myStuff.vec.push_back(L"TestingTestingTestingtestingTesting");
  
      {
      std::ofstream file("out.txt", std::ios::binary);
      cereal::BinaryOutputArchive output(file);
      output(myStuff);
      }
  
      {
          std::ifstream file("out.txt", std::ios::binary);
          cereal::BinaryInputArchive input(file);
          input(otherStuff);
      }
  
      int nSize = otherStuff.vec.size();
  
      for (int x = 0; x &lt; nSize; x++)
      {
          std::wcout &lt;&lt; (LPCWSTR)otherStuff.vec[x] &lt;&lt; std::endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>Thanks to Barmak Shemirani for the help.</p>