How can I clean this up?
std::wstring LinkResolve::ResolveLink( const std::wstring& source ) const
{
HRESULT errorCheck;
wchar_t linkTarget[MAX_PATH];
wchar_t expandedTarget[MAX_PATH];
wchar_t arguments[INFOTIPSIZE];
ATL::CComPtr<IPersistFile> ipf;
errorCheck = ipf.CoCreateInstance(CLSID_ShellLink, 0, CLSCTX_INPROC_SERVER);
if (!SUCCEEDED(errorCheck))
{
throw _com_error(errorCheck);
}
errorCheck = ipf->Load(source.c_str(), 0);
ATL::CComPtr<IShellLink> shellLink;
errorCheck = ipf->QueryInterface(&shellLink);
if (!SUCCEEDED(errorCheck))
{
throw _com_error(errorCheck);
}
errorCheck = shellLink->Resolve(0, SLR_NO_UI);
if (!SUCCEEDED(errorCheck))
{
throw _com_error(errorCheck);
}
errorCheck = shellLink->GetPath(linkTarget, MAX_PATH, 0, SLGP_RAWPATH);
if (!SUCCEEDED(errorCheck))
{
throw _com_error(errorCheck);
}
ExpandEnvironmentStringsW(linkTarget, expandedTarget, MAX_PATH);
errorCheck = shellLink->GetArguments(arguments, INFOTIPSIZE);
if (SUCCEEDED(errorCheck))
{
return std::wstring(expandedTarget) + L" " + arguments;
}
else
{
return expandedTarget;
}
}