szInPath의 바로가기를 그대로 szOutPath로 복사하는 함수입니다.
최대한 간단하게 로직만 적었으므로 사용할 때는 실패에 대한 처리를 해줘야 합니다.
예)
CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&link);

->

if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&link))) 

void CopyLinkPath(char *szInPath, char *szOutPath)
{
CoInitialize(NULL);

IShellLink *link;
IPersistFile *pfile;
BSTR szLinkPath;
int nIcon;
CString szPrePath;
char szOliPath[260];
char szArg[260];
char szDesc[260];
char szIconPath[260];
char szWorkDir[260];
int nShowCmd = 0;
WORD wHotKey = 0;
CString fname = szInPath;
CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&link);

link->QueryInterface(IID_IPersistFile, (void **)&pfile);
szLinkPath = fname.AllocSysString();
pfile->Load(szLinkPath, STGM_READ);
SysFreeString(szLinkPath);
link->Resolve(NULL, NULL);
link->GetPath(szOliPath, 260, NULL, 0);
link->GetArguments(szArg, 260);
link->GetDescription(szDesc, 260);
link->GetIconLocation(szIconPath, 260, &nIcon);
link->GetWorkingDirectory(szWorkDir, 260);
link->GetShowCmd(&nShowCmd);
link->GetHotkey(&wHotKey);
// 리스트 박스나 메세지 박스로 해당 경로 값을 불러온다. (szBuffer)
pfile->Release();
link->Release();



fname = szOutPath;

CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&link);

link->SetPath(szOliPath);
link->SetArguments(szArg);
link->SetDescription(szDesc);
link->SetIconLocation(szIconPath, nIcon);
link->SetWorkingDirectory(szWorkDir);
link->SetShowCmd(nShowCmd);
link->SetHotkey(wHotKey);

link->QueryInterface(IID_IPersistFile, (void **)&pfile);

szLinkPath = fname.AllocSysString();
pfile->Save(szLinkPath, TRUE);
SysFreeString(szLinkPath);

pfile->Release();
link->Release();

CoUninitialize();

}
Posted by 띠깜
,