直接贴代码~
#include <shellapi.h>
#include <shlobj.h>
#pragma comment(lib, "shell32.lib")
bool _ChangeLinkFile(CString strOrignPath, CString strAferPath)
{
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
IShellLink *pShellLink = NULL;
IPersistFile *pPf = NULL;
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pShellLink);
if (SUCCEEDED(hr))
{
hr = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&pPf);
if(!SUCCEEDED(hr))
return false;
hr =pPf->Load(strOrignPath, STGM_WRITE);
hr = pPf->Save(strAferPath, true);
::DeleteFile(strOrignPath);
pPf->Release();
pShellLink->Release();
}
CoUninitialize();
}
return false;
}
主要是通过IShellLink和IPersistFile俩个类的方法实现,可以查看msdn这俩的方法使用。