Last active
July 17, 2023 08:19
-
-
Save smourier/50673230c3756d5ee5f95f0080ee8f3c to your computer and use it in GitHub Desktop.
Delete a thumbnail (uses undocumented interface, use at your own risk)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
#include <atlbase.h> | |
#include <atlcom.h> | |
#include <thumbcache.h> | |
DECLARE_INTERFACE_IID_(IThumbnailCachePrivate, IUnknown, "3413b9cd-0db3-4e97-8bf4-68fb100d1815") | |
{ | |
public: | |
virtual HRESULT STDMETHODCALLTYPE Method0(); | |
virtual HRESULT STDMETHODCALLTYPE Method1(); | |
virtual HRESULT STDMETHODCALLTYPE Method2(); | |
virtual HRESULT STDMETHODCALLTYPE Method3(); | |
virtual HRESULT STDMETHODCALLTYPE Method4(); | |
virtual HRESULT STDMETHODCALLTYPE Method5(); | |
virtual HRESULT STDMETHODCALLTYPE DeleteThumbnail(WTS_THUMBNAILID) = 0; | |
}; | |
int main() | |
{ | |
CoInitialize(nullptr); | |
{ | |
CComPtr<IShellItem> item; | |
auto hr = SHCreateItemFromParsingName(L"c:\\somepath\\somefile.ext", nullptr, IID_PPV_ARGS(&item)); | |
wprintf(L"hr0:0x%08X\n", hr); | |
CComPtr<IThumbnailCache> cache; | |
hr = cache.CoCreateInstance(CLSID_LocalThumbnailCache); | |
wprintf(L"hr1:0x%08X\n", hr); | |
WTS_THUMBNAILID id; | |
hr = cache->GetThumbnail(item, 256, WTS_NONE, nullptr, nullptr, &id); | |
wprintf(L"hr3:0x%08X\n", hr); | |
CComPtr<IThumbnailCachePrivate> priv; | |
hr = cache.QueryInterface(&priv); | |
wprintf(L"hr4:0x%08X\n", hr); | |
hr = priv->DeleteThumbnail(id); | |
wprintf(L"hr5:0x%08X\n", hr); | |
} | |
CoUninitialize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment