From 40115052f14e4285bbc5bfa2de69a7bd51f5d13b Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Fri, 28 Aug 2015 17:31:03 +0000 Subject: AddToStartMenu: includes cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@15067 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AddToStartMenu/src/main.cpp | 38 +++++++++++++++---------------------- plugins/AddToStartMenu/src/stdafx.h | 7 ++----- 2 files changed, 17 insertions(+), 28 deletions(-) (limited to 'plugins/AddToStartMenu/src') diff --git a/plugins/AddToStartMenu/src/main.cpp b/plugins/AddToStartMenu/src/main.cpp index 5c4da0766c..6b3a86ebaa 100644 --- a/plugins/AddToStartMenu/src/main.cpp +++ b/plugins/AddToStartMenu/src/main.cpp @@ -99,49 +99,41 @@ HRESULT TryCreateShortcut() HRESULT InstallShortcut(_In_z_ wchar_t *shortcutPath) { wchar_t exePath[MAX_PATH]; + GetModuleFileName(NULL, exePath, MAX_PATH); - DWORD charWritten = GetModuleFileNameEx(GetCurrentProcess(), nullptr, exePath, ARRAYSIZE(exePath)); - - HRESULT hr = charWritten > 0 ? S_OK : E_FAIL; - + ComPtr shellLink; + HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); if (SUCCEEDED(hr)) { - ComPtr shellLink; - hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); - + hr = shellLink->SetPath(exePath); if (SUCCEEDED(hr)) { - hr = shellLink->SetPath(exePath); + hr = shellLink->SetArguments(L""); if (SUCCEEDED(hr)) { - hr = shellLink->SetArguments(L""); + ComPtr propertyStore; + hr = shellLink.As(&propertyStore); if (SUCCEEDED(hr)) { - ComPtr propertyStore; - - hr = shellLink.As(&propertyStore); + PROPVARIANT appIdPropVar; + hr = InitPropVariantFromString(AppUserModelID, &appIdPropVar); if (SUCCEEDED(hr)) { - PROPVARIANT appIdPropVar; - hr = InitPropVariantFromString(AppUserModelID, &appIdPropVar); + hr = propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar); if (SUCCEEDED(hr)) { - hr = propertyStore->SetValue(PKEY_AppUserModel_ID, appIdPropVar); + hr = propertyStore->Commit(); if (SUCCEEDED(hr)) { - hr = propertyStore->Commit(); + ComPtr persistFile; + hr = shellLink.As(&persistFile); if (SUCCEEDED(hr)) { - ComPtr persistFile; - hr = shellLink.As(&persistFile); - if (SUCCEEDED(hr)) - { - hr = persistFile->Save(shortcutPath, TRUE); - } + hr = persistFile->Save(shortcutPath, TRUE); } } - PropVariantClear(&appIdPropVar); } + PropVariantClear(&appIdPropVar); } } } diff --git a/plugins/AddToStartMenu/src/stdafx.h b/plugins/AddToStartMenu/src/stdafx.h index 587fba5c3a..439407cffe 100644 --- a/plugins/AddToStartMenu/src/stdafx.h +++ b/plugins/AddToStartMenu/src/stdafx.h @@ -1,12 +1,7 @@ #pragma once -#include -#include - #include #include -#include -#include #include #include #include @@ -15,6 +10,8 @@ #include #include "Version.h" +DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 5); + const wchar_t AppUserModelID[] = _T("MirandaNG"); #define MODULENAME "AddToStartMenu" -- cgit v1.2.3