+ TCHAR filepath[MAX_PATH+1];
+
+ _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
+ path, GetCurrentProcessId(), ++uniqueId);
+
+#ifdef _UNICODE
+ /* reuse path storage for UTF8 string */
+ char *psz_filepath = (char *)path;
+ WCHAR* wpath = filepath;
+#else
+ char *psz_filepath = path;
+ /* first convert to unicode using current code page */
+ WCHAR wpath[MAX_PATH+1];
+ if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) )
+ return E_FAIL;
+#endif
+ /* convert to UTF8 */
+ pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL);
+ // fail if path is 0 or too short (i.e pathlen is the same as storage size)
+ if( (0 == pathlen) || (sizeof(path) == pathlen) )
+ return E_FAIL;
+
+ /* take snapshot into file */
+ libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
+ libvlc_media_instance_release(p_md);