GPF when using stl string (typically in printf, wprintf, fprintf, fwprintf, sprintf, swprintf, _snprintf, _snwprintf, _vscprintf, _vscwprintf)

Description
It is possible to get an Unhandled exception 0xC0000005 when using stl string objects returned from generated objects. The problem is typically noticed when using printf, wprintf, fprintf, fwprintf, sprintf, swprintf, _snprintf, _snwprintf, _vscprintf, _vscwprintf family of instructions e.g.
printf("DVD Title = %s\n", dvd->GetTitle());


where dvd->GetTitle() returns an stl string.

The Problem
Because std::tstring is just the standard stl string hiding behind a typedef, we get a problem that is quite common, and not imediatley obvious what the cause is.

The stl string class does not have a const char* cast operator, so it can't be used as if it were a C++ string. Because of this when it is used within printf (or a similar function), the printf function attempts to treat it as a const char* (which it is not), and this causes problems that lead to a GPF (typically in output.c).

Solution
A reference to a const char * can be obtained from a stl string using the c_str() method. Use this method whenever you expect the stl string to be treated as a const char * (i.e. when used in printf etc.).
printf("DVD Title = %s\n", dvd->GetTitle().c_str());
Applies To
All Builds of Liquid XML DataBinder, when using Microsoft Visual C++ (all Versions)