+
+/* Converts a HRESULT error to a text string
+ * LPTSTR is either a */
+static gchar *
+gst_hres_to_string (HRESULT hRes)
+{
+ DWORD flags;
+ gchar *ret_text;
+ LPTSTR error_text = NULL;
+
+ flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER
+ | FORMAT_MESSAGE_IGNORE_INSERTS;
+ FormatMessage (flags, NULL, hRes, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) & error_text, 0, NULL);
+
+#ifdef UNICODE
+ /* If UNICODE is defined, LPTSTR is LPWSTR which is UTF-16 */
+ ret_text = g_utf16_to_utf8 (error_text, 0, NULL, NULL, NULL);
+#else
+ ret_text = g_strdup (error_text);
+#endif
+
+ LocalFree (error_text);
+ return ret_text;
+}