While MediaInfoDLL returns metadata (Sampling Rate, Channels, Stream Size, Title...) in std::basic_string<Char> format, I need to convert to string to be able to process it later. For example mi.Get(Stream_Audio, 0, __T("Performer")) returns "Artist Name" in std::basic_string<Char> format.
Can you help me?
Thank you in advance
Reading through the MediaInfoLib library's C++ code, it seems there are two possibilities. The library defines a type alias String, and this is the type you're seeing.
First, here is the definition of the Char and String types:
namespace MediaInfoLib {
/* ... */
//Char types
#undef __T
#define __T(__x) __T(__x)
#if defined(UNICODE) || defined (_UNICODE)
typedef wchar_t Char; ///< Unicode/Ansi independant char
#undef __T
#define __T(__x) L ## __x
#else
typedef char Char; ///< Unicode/Ansi independant char
#undef __T
#define __T(__x) __x
#endif
typedef std::basic_string<MediaInfoLib::Char> String; ///< Unicode/Ansi independant string
/* ... */
} // end namespace
If the macro UNICODE or _UNICODE was defined when the library was built, then the type is std::basic_string<wchar_t>, which is std::wstring in the standard library.
To convert this to std::string, please see this question:
How to convert wstring into string?
The simplest answer there uses std::wstring_convert.
If the macro UNICODE or _UNICODE was NOT defined when the library was built, then MediaInfoLib::Char is the type char, and the MediaInfoLib::String type is std::basic_string<char> is already std::string. That is, in this case, the return type is already std::string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With