1 // MediaInfoShellExt_.cpp : Implementation of CMediaInfoShellExt_
2 
3 #include "stdafx.h"
4 #include "MediaInfoShellExt_.h"
5 #include <MediaInfoDLL/MediaInfoDLL_Static.h>
6 
7 
8 // CMediaInfoShellExt_
9 
Load(LPCOLESTR wszFilename,DWORD)10 HRESULT CMediaInfoShellExt_::Load (LPCOLESTR wszFilename, DWORD)
11 {
12     //Save FileName
13     FileName = wszFilename;
14 
15     //OK
16     return S_OK;
17 }
18 
GetInfoTip(DWORD,LPWSTR * ppwszTip)19 HRESULT CMediaInfoShellExt_::GetInfoTip (DWORD, LPWSTR* ppwszTip)
20 {
21     LPMALLOC        Malloc;
22     std::wstring    ToolTip;
23 
24     //Get an IMalloc interface from the shell.
25     if (FAILED(SHGetMalloc(&Malloc)))
26         return E_FAIL;
27 
28     //Creating tooltip
29     ToolTip=_T("MediaInfo:\n");
30     MediaInfoDLL::MediaInfo I;
31     I.Option(_T("Inform"), _T("Summary"));
32     I.Open(FileName);
33     for (size_t StreamKind=0; StreamKind<(size_t)MediaInfoDLL::Stream_Max; StreamKind++)
34         for (size_t StreamPos=0; StreamPos<I.Count_Get((MediaInfoDLL::stream_t)StreamKind); StreamPos++)
35         {
36             if (StreamKind>0)
37             {
38                 ToolTip+=I.Get((MediaInfoDLL::stream_t)StreamKind, StreamPos, _T("StreamKind"));
39                 ToolTip+=_T(": ");
40             }
41             ToolTip+=I.Get((MediaInfoDLL::stream_t)StreamKind, StreamPos, _T("Inform"));
42             ToolTip+=_T("\r\n");
43         }
44     if (ToolTip.size()>2)
45         ToolTip.resize(ToolTip.size()-2); //Removing the ending \r\n
46 
47     //Allocate a buffer for Explorer.  Note that the must pass the string
48     //back as a Unicode string, so the string length is multiplied by the
49     //size of a Unicode character.
50     *ppwszTip=(LPWSTR)Malloc->Alloc((ToolTip.size()+1)*sizeof(wchar_t));
51 
52     //Release the IMalloc interface now that we're done using it.
53     Malloc->Release();
54 
55     //Enough memory?
56     if (*ppwszTip==NULL)
57         return E_OUTOFMEMORY;
58 
59     //Use the Unicode string copy function to put the tooltip text in the buffer.
60     wcscpy_s(*ppwszTip, ToolTip.size()+1, T2COLE(ToolTip.c_str()));
61 
62     //OK
63     return S_OK;
64 }