本文整理汇总了C++中IShellLink::GetPath方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellLink::GetPath方法的具体用法?C++ IShellLink::GetPath怎么用?C++ IShellLink::GetPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellLink
的用法示例。
在下文中一共展示了IShellLink::GetPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: int
std::string Shortcut_GetTarget(const char* szLink) {
wchar_t wszLink[MAX_PATH] = {};
::MultiByteToWideChar(CP_ACP, NULL, szLink, int(strlen(szLink)), wszLink, MAX_PATH);
char buf[MAX_PATH] = {};
IShellLink *pShellLink;
HRESULT hRes;
::CoInitialize(NULL);
hRes = CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(void **)&pShellLink);
if(SUCCEEDED(hRes)) {
IPersistFile *ppf;
hRes = pShellLink->QueryInterface(IID_IPersistFile,(void **)&ppf);
if(SUCCEEDED(hRes)) {
hRes = ppf->Load(wszLink, TRUE);
if(SUCCEEDED(hRes)) {
pShellLink->GetPath(buf, MAX_PATH, NULL, 0);
}
ppf->Release();
}
pShellLink->Release();
}
::CoUninitialize();
return std::string(buf);
}
示例2: GetShortCut
long GetShortCut( char *linkpath, char *newpath )
{
HRESULT hres;
IShellLink* psl;
WIN32_FIND_DATA fd;
CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink,(void**)&psl);
if (SUCCEEDED(hres)) {
IPersistFile *ppf;
hres = psl->QueryInterface (IID_IPersistFile, (void **)&ppf); //IID_IPersistFile
if (SUCCEEDED(hres)) {
WCHAR wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, linkpath, -1, wsz, MAX_PATH); // Load the shortcut.
hres = ppf->Load(wsz, TRUE);
if (SUCCEEDED(hres)) {
psl->GetPath(newpath ,256, &fd, SLGP_SHORTPATH );
}
ppf->Release();
if(!SUCCEEDED(hres))
return false;
} else
return false;
psl->Release();
} else
return false;
CoUninitialize();
return true;
}
示例3: ReadLinkV
BOOL ReadLinkV(void *src, void *dest, void *arg)
{
IShellLink *shellLink; // 実際は IShellLinkA or IShellLinkW
IPersistFile *persistFile;
WCHAR wbuf[MAX_PATH];
BOOL ret = FALSE;
if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkV,
(void **)&shellLink))) {
if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) {
if (!IS_WINNT_V) {
::MultiByteToWideChar(CP_ACP, 0, (char *)src, -1, wbuf, MAX_PATH);
src = wbuf;
}
if (SUCCEEDED(persistFile->Load((WCHAR *)src, STGM_READ))) {
if (SUCCEEDED(shellLink->GetPath((char *)dest, MAX_PATH, NULL, 0))) {
if (arg) {
shellLink->GetArguments((char *)arg, MAX_PATH);
}
ret = TRUE;
}
}
persistFile->Release();
}
shellLink->Release();
}
return ret;
}
示例4: ResolveShortcut
BOOL ResolveShortcut(TCHAR *shortcut, TCHAR *file)
{
IShellLink* psl = NULL;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl);
if (SUCCEEDED(hr)) {
IPersistFile* ppf = NULL;
hr = psl->QueryInterface(IID_IPersistFile, (void **) &ppf);
if (SUCCEEDED(hr)) {
hr = ppf->Load(shortcut, STGM_READ);
if (SUCCEEDED(hr)) {
hr = psl->Resolve(NULL, SLR_UPDATE);
if (SUCCEEDED(hr)) {
WIN32_FIND_DATA wfd;
hr = psl->GetPath(file, MAX_PATH, &wfd, SLGP_RAWPATH);
}
}
ppf->Release();
}
psl->Release();
}
return SUCCEEDED(hr);
}
示例5: ReadLinkU8
/*
リンクの解決
あらかじめ、CoInitialize(NULL); を実行しておくこと
*/
BOOL ReadLinkU8(LPCSTR src, LPSTR dest, LPSTR arg)
{
IShellLink *shellLink;
IPersistFile *persistFile;
WCHAR wbuf[MAX_PATH];
BOOL ret = FALSE;
if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW,
(void **)&shellLink)))
{
if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile)))
{
U8toW(src, wbuf, wsizeof(wbuf));
if (SUCCEEDED(persistFile->Load(wbuf, STGM_READ)))
{
if (SUCCEEDED(shellLink->GetPath((char *)wbuf, MAX_PATH, NULL, SLGP_SHORTPATH)))
{
WtoU8(wbuf, dest, MAX_PATH_U8);
shellLink->GetArguments((char *)wbuf, MAX_PATH);
WtoU8(wbuf, arg, MAX_PATH_U8);
ret = TRUE;
}
}
persistFile->Release();
}
shellLink->Release();
}
return ret;
}
示例6: CoCreateInstance
static bool sGetSymLinkPath0(const char *linkpath, String *path)
{
bool ret = false;
HRESULT hres;
IShellLink* psl;
IPersistFile* ppf;
CoInitialize(NULL);
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
(PVOID *) &psl);
if(SUCCEEDED(hres)) {
hres = psl->QueryInterface(IID_IPersistFile, (PVOID *) &ppf);
if(SUCCEEDED(hres)) {
hres = ppf->Load(ToSystemCharsetW(linkpath), STGM_READ);
if(SUCCEEDED(hres))
if(path) {
char fileW[_MAX_PATH] = {0};
psl->GetPath(fileW, _MAX_PATH, NULL, 0);
*path = FromSystemCharset(fileW);
}
else
ret = true;
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return ret;
}
示例7: ResolveShortcut
HRESULT ShellFunctions::ResolveShortcut(HWND hWnd,LPCSTR pszShortcutFile,LPSTR pszPath)
{
HRESULT hres;
IShellLink* psl;
pszPath[0]='\0';
hres=CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(void**)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
hres=psl->QueryInterface(IID_IPersistFile,(void**)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP,0,pszShortcutFile,-1,wsz,MAX_PATH);
hres=ppf->Load(wsz,STGM_READ);
if (SUCCEEDED(hres))
{
hres=psl->Resolve(hWnd,SLR_ANY_MATCH);
if (pszPath!=NULL && SUCCEEDED(hres))
hres=psl->GetPath(pszPath,MAX_PATH,NULL,0);
}
ppf->Release();
}
psl->Release();
}
return hres;
}
示例8: ResolveShortcut
CString FileMisc::ResolveShortcut(LPCTSTR szShortcut)
{
// start by checking its a valid file
if (!FileExists(szShortcut))
{
return _T("");
}
CoInitialize(NULL);
HRESULT hResult;
IShellLink* psl;
CString sTarget(szShortcut);
hResult = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hResult))
{
LPPERSISTFILE ppf;
hResult = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hResult))
{
hResult = ppf->Load(ATL::CT2OLE(szShortcut), STGM_READ);
if (SUCCEEDED(hResult))
{
hResult = psl->Resolve(NULL, SLR_ANY_MATCH | SLR_NO_UI);
if (SUCCEEDED(hResult))
{
TCHAR szPath[MAX_PATH];
WIN32_FIND_DATA wfd;
//fabio_2005
#if _MSC_VER >= 1400
_tcscpy_s(szPath, szShortcut);
#else
_tcscpy(szPath, szShortcut);
#endif
hResult = psl->GetPath(szPath, MAX_PATH, (WIN32_FIND_DATA*)&wfd, SLGP_SHORTPATH);
if (SUCCEEDED(hResult))
{
sTarget = CString(szPath);
}
}
}
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return sTarget;
}
示例9: OnDropFiles
void CEzShortcutDlg::OnDropFiles(HDROP hDropInfo)
{
TCHAR szPathName[MAX_PATH];
// 드롭된 파일의 갯수
int nFiles=DragQueryFile(hDropInfo, 0xFFFFFFFF, szPathName, MAX_PATH);
if( nFiles != 1)
{
AfxMessageBox(_T("This application is not support multi-file drag & drop"));
return;
}
for(int index=0 ; index < nFiles ; index++)
{
DragQueryFile(hDropInfo, index, szPathName, MAX_PATH); // 파일의 경로 얻어옴
std::wstring strExt = light::get_file_ext(szPathName);
if( strExt == _T("lnk" ))
{
IShellLink *link;
IPersistFile *pfile;
BSTR szLinkPath;
CString szPrePath;
TCHAR szBuffer[MAX_PATH];
CString fname = szPathName;
if(SUCCEEDED(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(szBuffer, MAX_PATH, NULL, 0);
// 리스트 박스나 메세지 박스로 해당 경로 값을 불러온다. (szBuffer)
_tcsncpy_s(szPathName , szBuffer, _TRUNCATE);
pfile->Release();
link->Release();
}
}
SHORTCUT_INFO ShortcutInfo(GetSafeHwnd());
ShortcutInfo.m_strShortcutName = light::get_file_name_without_ext(szPathName);
ShortcutInfo.m_strProgramPath = szPathName;
if( true == OnEditShortcutDlg(ShortcutInfo) )
{
AddShortCutInfo(ShortcutInfo);
RebuildShortcutList();
AutoSave();
}
}
DragFinish(hDropInfo);
CDialog::OnDropFiles(hDropInfo);
}
示例10: ResolveShortcut
HRESULT ResolveShortcut(const TCHAR* LnkFile, TCHAR* FilePath,
TCHAR* LnkDesc, TCHAR* WorkDir)
{
CoInitialize(NULL);
HRESULT hres;
IShellLink* psl;
WIN32_FIND_DATA wfd;
TCHAR strfilepath[MAX_PATH];
TCHAR strlnkdesc[INFOTIPSIZE];
TCHAR strworkdir[MAX_PATH];
USES_CONVERSION;
hres = CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf);
if (SUCCEEDED(hres))
{
hres = ppf->Load(LnkFile, STGM_READ);
if (SUCCEEDED(hres))
{
hres = psl->Resolve(GetDesktopWindow(), 0);
if (SUCCEEDED(hres))
{
hres = psl->GetPath(strfilepath,MAX_PATH, &wfd,
SLGP_UNCPRIORITY );
if (SUCCEEDED(hres))
{
_tcscpy(FilePath, strfilepath);
hres = psl->GetDescription(strlnkdesc,INFOTIPSIZE);
}
if (SUCCEEDED(hres))
{
_tcscpy(LnkDesc,strlnkdesc);
hres = psl->GetWorkingDirectory(strworkdir,MAX_PATH);
}
if (SUCCEEDED(hres))
{
_tcscpy(WorkDir,strworkdir);
}
}
}
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return hres;
}
示例11: GetShortcutInfo
/** Get shortcut info on current file
*
* @param[in] pszPathShortcut path to shortcut file
* @param[out] pszPathTarget variable to be set to shortcut's target path
* @param[in] cchMaxPath length of pszPathTarget buffer, in characters
* @param[out] psFd shortcut's target info
*
* @returns successful @b HRESULT on success, else failing @b HRESULT on
* on error or if the current file is not a link.
*/
HRESULT CFileIterator::GetShortcutInfo(LPCTSTR pszPathShortcut, LPTSTR pszPathTarget, int cchMaxPath, WIN32_FIND_DATA* psFd) const
{
// try opening the link...
IShellLink* piLink;
HRESULT hr = OpenLink(pszPathShortcut, &piLink);
if (SUCCEEDED(hr))
{
// Get the path to the link target.
hr = piLink->GetPath(pszPathTarget, cchMaxPath, psFd, SLGP_UNCPRIORITY);
piLink->Release();
}
return hr;
}
示例12: ResolveShortcut
//Taken from: http://www.cplusplus.com/forum/windows/64088/
bool ResolveShortcut(HWND hwnd, const wchar_t* szShortcutPath, char* szResolvedPath, size_t nSize)
{
if(szResolvedPath == NULL)
return SUCCEEDED(E_INVALIDARG);
//Initialize COM stuff
CoInitialize(NULL);
//Get a pointer to the IShellLink interface.
IShellLink* psl = NULL;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if(SUCCEEDED(hres))
{
//Get a pointer to the IPersistFile interface.
IPersistFile* ppf = NULL;
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if(SUCCEEDED(hres))
{
//Load the shortcut.
hres = ppf->Load(szShortcutPath, STGM_READ);
if(SUCCEEDED(hres))
{
//Resolve the link.
hres = psl->Resolve(hwnd, 0);
if(SUCCEEDED(hres))
{
//Get the path to the link target.
char szGotPath[MAX_PATH] = {0};
hres = psl->GetPath(szGotPath, _countof(szGotPath), NULL, SLGP_SHORTPATH);
if(SUCCEEDED(hres))
{
strcpy_s(szResolvedPath, nSize, szGotPath);
}
}
}
//Release the pointer to the IPersistFile interface.
ppf->Release();
}
//Release the pointer to the IShellLink interface.
psl->Release();
}
//Uninitialize COM stuff
CoUninitialize();
return SUCCEEDED(hres);
}
示例13: AfxResolveShortcut
BOOL AFXAPI AfxResolveShortcut(CWnd* pWnd, LPCTSTR lpszFileIn,
LPTSTR lpszFileOut, int cchPath)
{
USES_CONVERSION;
AFX_COM com;
IShellLink* psl;
*lpszFileOut = 0; // assume failure
// WINBUG: Win32s versions prior to Win32s 1.3b do not restore the
// stack pointer correctly in SHGetFileInfo. All it does is return
// failure anyway on Win32s, so here we just avoid calling it.
if (afxData.bWin31)
return FALSE;
SHFILEINFO info;
if ((SHGetFileInfo(lpszFileIn, 0, &info, sizeof(info),
SHGFI_ATTRIBUTES) == 0) || !(info.dwAttributes & SFGAO_LINK))
{
return FALSE;
}
if (FAILED(com.CreateInstance(CLSID_ShellLink, NULL, IID_IShellLink,
(LPVOID*)&psl)))
{
return FALSE;
}
IPersistFile *ppf;
if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf)))
{
if (SUCCEEDED(ppf->Load(T2COLE(lpszFileIn), STGM_READ)))
{
/* Resolve the link, this may post UI to find the link */
if (SUCCEEDED(psl->Resolve(pWnd->GetSafeHwnd(),
SLR_ANY_MATCH)))
{
//#ifndef _UNICODE
psl->GetPath(lpszFileOut, cchPath, NULL, 0);
/*#else
char szTemp[_MAX_PATH];
psl->GetPath(szTemp, _MAX_PATH, NULL, 0);
_mbstowcsz(lpszFileOut, szTemp, cchPath);
#endif*/
return TRUE;
}
}
ppf->Release();
}
psl->Release();
return FALSE;
}
示例14: ResolveLink
HRESULT ResolveLink(HWND hwnd,DWORD fFlags,TCHAR *LinkFile,TCHAR *LinkPath,int nBufferSize)
{
IShellLink *pShellLink = NULL;
IPersistFile *pPersistFile = NULL;
SHFILEINFO shfi;
WCHAR LinkFileW[MAX_PATH];
TCHAR ResolvedFilePath[MAX_PATH];
HRESULT hr;
SHGetFileInfo(LinkFile,NULL,&shfi,sizeof(shfi),SHGFI_ATTRIBUTES);
if(!(shfi.dwAttributes & SFGAO_LINK))
{
StringCchCopy(LinkPath,nBufferSize,LinkFile);
return E_UNEXPECTED;
}
hr = CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,
IID_IShellLink,(LPVOID*)&pShellLink);
if(hr == S_OK)
{
hr = pShellLink->QueryInterface(IID_IPersistFile,(LPVOID *)&pPersistFile);
if(hr == S_OK)
{
#ifndef UNICODE
MultiByteToWideChar(CP_ACP,0,LinkFile,-1,LinkFileW,MAX_PATH);
#else
StringCchCopy(LinkFileW,SIZEOF_ARRAY(LinkFileW),LinkFile);
#endif
hr = pPersistFile->Load(LinkFileW,STGM_READ);
if(hr == S_OK)
{
pShellLink->Resolve(hwnd,fFlags);
pShellLink->GetPath(ResolvedFilePath,MAX_PATH,NULL,SLGP_UNCPRIORITY);
StringCchCopy(LinkPath,nBufferSize,ResolvedFilePath);
}
pPersistFile->Release();
}
pShellLink->Release();
}
return hr;
}
示例15: ExpandShortcut
CString CDropEdit::ExpandShortcut(CString &inFile)
{
CString outFile = "";
// Make sure we have a path
ASSERT(inFile != _T(""));
IShellLink* psl;
HRESULT hres;
LPTSTR lpsz = inFile.GetBuffer(MAX_PATH);
// Create instance for shell link
hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*) &psl);
if (SUCCEEDED(hres))
{
// Get a pointer to the persist file interface
IPersistFile* ppf;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*) &ppf);
if (SUCCEEDED(hres))
{
// Make sure it's ANSI
WCHAR wsz[MAX_PATH];
::MultiByteToWideChar(CP_ACP, 0, lpsz, -1, wsz, MAX_PATH);
// Load shortcut
hres = ppf->Load(wsz, STGM_READ);
if (SUCCEEDED(hres)) {
WIN32_FIND_DATA wfd;
// find the path from that
HRESULT hres = psl->GetPath(outFile.GetBuffer(MAX_PATH),
MAX_PATH,
&wfd,
SLGP_UNCPRIORITY);
outFile.ReleaseBuffer();
}
ppf->Release();
}
psl->Release();
}
inFile.ReleaseBuffer();
// if this fails, outFile == ""
return outFile;
}