* @brief Implementation file for JumpList helper functions.
*
*/
+#include "pch.h"
#include "JumpList.h"
#include <vector>
-#include <ObjBase.h>
-#include <ShlObj.h>
-#if _MSC_VER >= 1600
+#pragma warning (push) // prevent "warning C4091: 'typedef ': ignored on left of 'tagGPFIDL_FLAGS' when no variable is declared"
+#pragma warning (disable:4091) // VC bug when using XP enabled toolsets.
+#include <shlobj.h>
+#pragma warning (pop)
#include <propvarutil.h>
#include <propkey.h>
-#endif
#include "unicoder.h"
namespace
IShellLinkW *CreateShellLink(const std::wstring& app_path, const std::wstring& params, const std::wstring& title, const std::wstring& desc, int icon_index)
{
-#if _MSC_VER >= 1600
- IShellLinkW *pShellLink = NULL;
- if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
+ IShellLinkW *pShellLink = nullptr;
+ if (FAILED(CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER,
IID_IShellLinkW, (void **)&pShellLink)))
- return NULL;
+ return nullptr;
std::wstring app_path2(app_path);
if (app_path.empty())
{
if (g_exe_path[0] == '\0')
- GetModuleFileNameW(NULL, g_exe_path, sizeof(g_exe_path));
+ GetModuleFileNameW(nullptr, g_exe_path, sizeof(g_exe_path)/sizeof(g_exe_path[0]));
app_path2 = g_exe_path;
}
pShellLink->SetPath(app_path2.c_str());
pShellLink->SetArguments(params.c_str());
pShellLink->SetDescription(desc.c_str());
- IPropertyStore *pPS = NULL;
+ IPropertyStore *pPS = nullptr;
if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
{
PROPVARIANT pv;
- InitPropVariantFromString(title.c_str(), &pv);
- pPS->SetValue(PKEY_Title, pv);
- PropVariantClear(&pv);
+ if (SUCCEEDED(InitPropVariantFromString(title.c_str(), &pv)))
+ {
+ pPS->SetValue(PKEY_Title, pv);
+ PropVariantClear(&pv);
+ }
pPS->Commit();
pPS->Release();
}
return pShellLink;
-#else
- return NULL;
-#endif
}
}
{
g_appid = appid;
HMODULE hLibrary = GetModuleHandle(_T("shell32.dll"));
- if (!hLibrary)
+ if (hLibrary == nullptr)
return false;
HRESULT (__stdcall *pfnSetCurrentProcessExplicitAppUserModelID)(PCWSTR AppID) =
(HRESULT (__stdcall *)(PCWSTR))GetProcAddress(hLibrary, "SetCurrentProcessExplicitAppUserModelID");
- if (!pfnSetCurrentProcessExplicitAppUserModelID)
+ if (pfnSetCurrentProcessExplicitAppUserModelID == nullptr)
return false;
return pfnSetCurrentProcessExplicitAppUserModelID(appid.c_str()) == S_OK;
}
bool AddToRecentDocs(const String& app_path, const String& params, const String& title, const String& desc, int icon_index)
{
-#if _MSC_VER >= 1600
SHARDAPPIDINFOLINK saiil;
saiil.pszAppID = g_appid.c_str();
-#ifdef _UNICODE
saiil.psl = CreateShellLink(app_path, params, title, desc, icon_index);
-#else
- saiil.psl = (IShellLink *)CreateShellLink(ucr::toUTF16(app_path), ucr::toUTF16(params), ucr::toUTF16(title), ucr::toUTF16(desc), icon_index);
-#endif
- if (!saiil.psl)
+ if (saiil.psl == nullptr)
return false;
SHAddToRecentDocs(SHARD_APPIDINFOLINK, &saiil);
saiil.psl->Release();
return true;
-#else
- return false;
-#endif
}
std::vector<Item> GetRecentDocs(size_t nMaxItems)
{
std::vector<Item> list;
-#if _MSC_VER >= 1600
- IApplicationDocumentLists *pDocumentLists = NULL;
- if (FAILED(CoCreateInstance(CLSID_ApplicationDocumentLists, NULL, CLSCTX_INPROC_SERVER,
+ IApplicationDocumentLists *pDocumentLists = nullptr;
+ if (FAILED(CoCreateInstance(CLSID_ApplicationDocumentLists, nullptr, CLSCTX_INPROC_SERVER,
IID_IApplicationDocumentLists, (void **)&pDocumentLists)))
return list;
pDocumentLists->SetAppID(g_appid.c_str());
if (SUCCEEDED(pDocumentLists->GetList(ADLT_RECENT, static_cast<UINT>(nMaxItems), IID_IObjectArray, (void **)&pObjectArray)))
{
UINT nObjects;
- pObjectArray->GetCount(&nObjects);
- for (UINT i = 0; i < nObjects; ++i)
+ if (SUCCEEDED(pObjectArray->GetCount(&nObjects)))
{
- IShellLinkW *pShellLink;
- if (SUCCEEDED(pObjectArray->GetAt(i, IID_IShellLinkW, (void **)&pShellLink)))
+ for (UINT i = 0; i < nObjects; ++i)
{
- wchar_t szPath[MAX_PATH];
- wchar_t szDescription[MAX_PATH];
- wchar_t szArguments[MAX_PATH * 6];
- pShellLink->GetPath(szPath, sizeof(szPath), NULL, SLGP_RAWPATH);
- pShellLink->GetDescription(szDescription, sizeof(szDescription));
- pShellLink->GetArguments(szArguments, sizeof(szArguments));
- IPropertyStore *pPS = NULL;
- PROPVARIANT pv;
- InitPropVariantFromString(_T(""), &pv);
- if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
+ IShellLinkW *pShellLink;
+ if (SUCCEEDED(pObjectArray->GetAt(i, IID_IShellLinkW, (void **)&pShellLink)))
{
- pPS->GetValue(PKEY_Title, &pv);
- pPS->Release();
+ wchar_t szPath[MAX_PATH];
+ wchar_t szDescription[MAX_PATH];
+ wchar_t szArguments[MAX_PATH * 6];
+ pShellLink->GetPath(szPath, sizeof(szPath) / sizeof(szPath[0]), nullptr, SLGP_RAWPATH);
+ pShellLink->GetDescription(szDescription, sizeof(szDescription) / sizeof(szDescription[0]));
+ pShellLink->GetArguments(szArguments, sizeof(szArguments) / sizeof(szArguments[0]));
+ IPropertyStore *pPS = nullptr;
+ if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
+ {
+ PROPVARIANT pv;
+ PropVariantInit(&pv);
+ if (SUCCEEDED(pPS->GetValue(PKEY_Title, &pv)))
+ {
+ list.push_back(Item(ucr::toTString(szPath), ucr::toTString(szArguments), ucr::toTString(pv.bstrVal), ucr::toTString(szDescription)));
+ PropVariantClear(&pv);
+ }
+ pPS->Release();
+ }
+ pShellLink->Release();
}
- list.push_back(Item(ucr::toTString(szPath), ucr::toTString(szArguments), ucr::toTString(pv.bstrVal), ucr::toTString(szDescription)));
- PropVariantClear(&pv);
- pShellLink->Release();
- }
+ }
}
pObjectArray->Release();
}
pDocumentLists->Release();
-#endif
return list;
}