HRESULT CreateShellLink(PCWSTR pszArguments, PCWSTR pszTitle, int iconIndex, IShellLink **ppsl)
{
	ATL::CComPtr<IShellLink> psl;
	HRESULT hr = psl.CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER);
	if (FAILED(hr))
		return hr;

	WCHAR szAppPath[MAX_PATH] = {0};
	if (GetModuleFileName(nullptr, szAppPath, ARRAYSIZE(szAppPath)) == 0)
	{
		hr = HRESULT_FROM_WIN32(GetLastError());
		return hr;
	}
	hr = psl->SetPath(szAppPath);
	if (FAILED(hr))
		return hr;

	hr = psl->SetArguments(pszArguments);
	if (FAILED(hr))
		return hr;

	hr = psl->SetIconLocation(szAppPath, iconIndex);
	if (FAILED(hr))
		return hr;

	ATL::CComPtr<IPropertyStore> pps;
	hr = psl.QueryInterface(&pps);
	if (FAILED(hr))
		return hr;

	PROPVARIANT propvar;
	hr = InitPropVariantFromString(pszTitle, &propvar);
	if (SUCCEEDED(hr))
	{
		hr = pps->SetValue(PKEY_Title, propvar);
		if (SUCCEEDED(hr)) {
			hr = pps->Commit();
			if (SUCCEEDED(hr)) {
				hr = psl.QueryInterface(ppsl);
			}
		}
		PropVariantClear(&propvar);
	}
	return hr;
}
Exemple #2
0
//
// IClassFactory implementation
//
HRESULT __stdcall CFactory::CreateInstance(IUnknown* pUnknownOuter, const IID& iid, void** ppv)
{
	if (!ppv)
		return E_POINTER;

	// Cannot aggregate.
	if (pUnknownOuter)
		return CLASS_E_NOAGGREGATION ;

	// Create component.
	ATL::CComPtr<GitWCRev> pA;
	pA.Attach(new (std::nothrow) GitWCRev()); // refcount set to 1 in constructor
	if (!pA)
		return E_OUTOFMEMORY ;

	return pA->QueryInterface(iid, ppv);
}
void CTortoiseProcApp::DoInitializeJumpList(const CString& appid)
{
	ATL::CComPtr<ICustomDestinationList> pcdl;
	HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
	if (FAILED(hr))
		return;

	hr = pcdl->SetAppID(appid);
	if (FAILED(hr))
		return;

	UINT uMaxSlots;
	ATL::CComPtr<IObjectArray> poaRemoved;
	hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
	if (FAILED(hr))
		return;

	ATL::CComPtr<IObjectCollection> poc;
	hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
	if (FAILED(hr))
		return;

	CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
	CStringUtils::RemoveAccelerators(sTemp);

	ATL::CComPtr<IShellLink> psl;
	hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
	if (SUCCEEDED(hr)) {
		poc->AddObject(psl);
	}
	sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
	CStringUtils::RemoveAccelerators(sTemp);
	psl.Release(); // Need to release the object before calling operator&()
	hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
	if (SUCCEEDED(hr)) {
		poc->AddObject(psl);
	}

	ATL::CComPtr<IObjectArray> poa;
	hr = poc.QueryInterface(&poa);
	if (SUCCEEDED(hr)) {
		pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
		pcdl->CommitList();
	}
}
HRESULT CreateSeparatorLink(IShellLink **ppsl)
{
	ATL::CComPtr<IPropertyStore> pps;
	HRESULT hr = pps.CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER);
	if (FAILED(hr))
		return hr;

	PROPVARIANT propvar;
	hr = InitPropVariantFromBoolean(TRUE, &propvar);
	if (FAILED(hr))
		return hr;

	hr = pps->SetValue(PKEY_AppUserModel_IsDestListSeparator, propvar);
	if (SUCCEEDED(hr)) {
		hr = pps->Commit();
		if (SUCCEEDED(hr))
		{
			hr = pps.QueryInterface(ppsl);
		}
	}
	PropVariantClear(&propvar);
	return hr;
}