当前位置: 首页>>代码示例>>C++>>正文


C++ IShellLink::Resolve方法代码示例

本文整理汇总了C++中IShellLink::Resolve方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellLink::Resolve方法的具体用法?C++ IShellLink::Resolve怎么用?C++ IShellLink::Resolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IShellLink的用法示例。


在下文中一共展示了IShellLink::Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:noindom99,项目名称:repositorium,代码行数:60,代码来源:FileMisc.cpp

示例2: 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;
}
开发者ID:quachdnguyen,项目名称:locate-src,代码行数:28,代码来源:Shell.cpp

示例3: 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);
}
开发者ID:ybznek,项目名称:miranda-ng,代码行数:27,代码来源:utils.cpp

示例4: 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);
}
开发者ID:elky84,项目名称:ez_shortcut,代码行数:57,代码来源:EzShortcutDlg.cpp

示例5: 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; 
} 
开发者ID:Cache22,项目名称:Launchy,代码行数:55,代码来源:Explory.cpp

示例6: 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;
}
开发者ID:rickerliang,项目名称:OpenNT,代码行数:51,代码来源:filecore.cpp

示例7: 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);
}
开发者ID:V10git,项目名称:x64dbg,代码行数:52,代码来源:_global.cpp

示例8: 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;
}
开发者ID:yellowbigbird,项目名称:bird-self-lib,代码行数:50,代码来源:FileOperations.c

示例9: common_getLnkPath

//获得快捷方式文件所指向的路径
//lpwsLinkName:lnk文件的路径
//lpwsLinkPath:用于存放所指程序路径的缓冲区
//返回:HRESULT
HRESULT common_getLnkPath(IN LPWSTR lpwsLinkName,OUT LPWSTR lpwsLinkPath)
{
	HRESULT hResult;
	IShellLink *pIShellLink;
	WIN32_FIND_DATA wfd;

	//初始化
	CoInitialize(NULL);
	//创建实例
	hResult = CoCreateInstance((REFIID)CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,(REFIID)IID_IShellLink,(LPVOID *)&pIShellLink);

	//如果成功
	if (SUCCEEDED(hResult))
	{
		IPersistFile *pIPersistFile;
		//查询相关信息
		hResult = pIShellLink->QueryInterface((REFIID)IID_IPersistFile,(LPVOID *)&pIPersistFile);

		//如果查询成功
		if (SUCCEEDED(hResult))
		{
			//加载快捷方式文件
			hResult = pIPersistFile->Load(lpwsLinkName, STGM_READ);

			//如果成功
			if (SUCCEEDED(hResult))
			{
				//解析
				hResult = pIShellLink->Resolve(NULL,SLR_ANY_MATCH | SLR_NO_UI);

				if (SUCCEEDED(hResult))
				{
					//获得快捷方式的制定的路径
					hResult = pIShellLink->GetPath(lpwsLinkPath,MAX_PATH,&wfd,SLGP_SHORTPATH);
				}

			}

			pIPersistFile->Release();
		}

		pIShellLink->Release();
	}

	return hResult;
}
开发者ID:340211173,项目名称:deianeira,代码行数:50,代码来源:common.cpp

示例10: OleSetOleError

// @pymethod |PyIShellLink|Resolve|Resolves a shell link by searching for the shell link object and updating the
// shell link path and its list of identifiers (if necessary)
PyObject *PyIShellLink::Resolve(PyObject *self, PyObject *args)
{
	IShellLink *pISL = GetI(self);
	if ( pISL == NULL )
		return NULL;
	// @pyparm HWND|hwnd||The parent window of a dialog which will pop up if resolution fails.
	// @pyparm int|fFlags||One of the following constants:
	// @flagh Value|Description
	// @flag SLR_INVOKE_MSI|Call the Microsoft Windows Installer. 
	// @flag SLR_NOLINKINFO |Disable distributed link tracking. By default, distributed
	//			link tracking tracks removable media across multiple devices based on the
	//			volume name. It also uses the UNC path to track remote file systems whose
	//			drive letter has changed. Setting SLR_NOLINKINFO disables both types of tracking. 
	// @flag SLR_NO_UI|Do not display a dialog box if the link cannot be resolved. When
	//			SLR_NO_UI is set, the high-order word of fFlags can be set to a time-out value
	//			that specifies the maximum amount of time to be spent resolving the link. The
	//			function returns if the link cannot be resolved within the time-out duration.
	//			If the high-order word is set to zero, the time-out duration will be set to the
	//			default value of 3,000 milliseconds (3 seconds). To specify a value, set the high
	//			word of fFlags to the desired time-out duration, in milliseconds. 
	// @flag SLR_NOUPDATE|Do not update the link information. 
	// @flag SLR_NOSEARCH|Do not execute the search heuristics. 
	// @flag SLR_NOTRACK|Do not use distributed link tracking. 
	// @flag SLR_UPDATE|If the link object has changed, update its path and list of identifiers. If SLR_UPDATE is set, you do not need to call IPersistFile::IsDirty to determine whether or not the link object has changed. 

	HWND hwnd;
	PyObject *obhwnd;
	DWORD fFlags;
	if ( !PyArg_ParseTuple(args, "Ol:Resolve", &obhwnd, &fFlags) )
		return NULL;
	if (!PyWinObject_AsHANDLE(obhwnd, (HANDLE *)&hwnd))
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pISL->Resolve( hwnd, fFlags );
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return OleSetOleError(hr);
	Py_INCREF(Py_None);
	return Py_None;

}
开发者ID:DavidGuben,项目名称:rcbplayspokemon,代码行数:45,代码来源:PyIShellLink.cpp

示例11: ResolveShortcut

BOOL ResolveShortcut(TCHAR *shortcut, TCHAR *file)
{
	CoInitialize(NULL);

    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))
		{
#ifdef _UNICODE
			hr = ppf->Load(shortcut, STGM_READ); 
#else
			WCHAR tmp[MAX_PATH]; 
			MultiByteToWideChar(CP_ACP, 0, shortcut, -1, tmp, MAX_PATH); 
			hr = ppf->Load(tmp, STGM_READ); 
#endif

			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(); 
    }

	if(FAILED(hr))
		ErrorExit(NULL,_T("CreateShortcut"));
	return SUCCEEDED(hr);
}
开发者ID:Robyer,项目名称:miranda-plugins,代码行数:43,代码来源:AvatarHistory.cpp

示例12: checkResolveLink

//-----------------------------------------------------------------------------
bool WinDragContainer::checkResolveLink (const TCHAR* nativePath, TCHAR* resolved)
{
	const TCHAR* ext = VSTGUI_STRRCHR (nativePath, '.');
	if (ext && VSTGUI_STRICMP (ext, TEXT(".lnk")) == 0)
	{
		IShellLink* psl;
		IPersistFile* ppf;
		WIN32_FIND_DATA wfd;
		HRESULT hres;
		
		// Get a pointer to the IShellLink interface.
		hres = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
			IID_IShellLink, (void**)&psl);
		if (SUCCEEDED (hres))
		{
			// Get a pointer to the IPersistFile interface.
			hres = psl->QueryInterface (IID_IPersistFile, (void**)&ppf);
			if (SUCCEEDED (hres))
			{
				// Load the shell link.
				hres = ppf->Load (nativePath, STGM_READ);
				if (SUCCEEDED (hres))
				{					
					hres = psl->Resolve (0, MAKELONG (SLR_ANY_MATCH | SLR_NO_UI, 500));
					if (SUCCEEDED (hres))
					{
						// Get the path to the link target.
						hres = psl->GetPath (resolved, 2048, &wfd, SLGP_SHORTPATH);
					}
				}
				// Release pointer to IPersistFile interface.
				ppf->Release ();
			}
			// Release pointer to IShellLink interface.
			psl->Release ();
		}
		return SUCCEEDED(hres);
	}
	return false;	
}
开发者ID:Piticfericit,项目名称:vstgui,代码行数:41,代码来源:win32dragcontainer.cpp

示例13: ResolveIt

STDAPI ResolveIt(HWND hwnd, LPCTSTR lpszLinkFile, LPTSTR lpszPath)
{
	HRESULT hres;
	IShellLink *psl;
	WIN32_FIND_DATA fd;
	*lpszPath = _T('\0'); // assume failure

	// Get a pointer to the IShellLink interface.
	hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
	if (SUCCEEDED(hres))
	{
		IPersistFile* ppf;
		// Get a pointer to the IPersistFile interface.
		hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
		if (SUCCEEDED(hres))
		{
			// Load the shortcut.
			hres = ppf->Load(static_cast<T2W>(lpszLinkFile), STGM_READ);
			if (SUCCEEDED(hres))
			{
				// Resolve the link.
				hres = psl->Resolve(hwnd, SLR_ANY_MATCH);
				if (SUCCEEDED(hres))
				{
					// Get the path to the link target.
					hres = psl->GetPath(lpszPath, MAX_PATH, &fd, SLGP_SHORTPATH);
				}
			}
			// Release the pointer to the IPersistFile interface.
			ppf->Release();
		}
		// Release the pointer to the IShellLink interface.
		psl->Release();
	}
	return hres;
}
开发者ID:derekdreery,项目名称:frhed,代码行数:36,代码来源:shtools.cpp

示例14: ResolveSymlink

//----------------------------------------------------------------------------------------
nsresult nsFileSpec::ResolveSymlink(PRBool& wasSymlink)
//----------------------------------------------------------------------------------------
{
    wasSymlink = PR_FALSE;  // assume failure

	if (Exists())
		return NS_OK;


    HRESULT hres; 
    IShellLink* psl; 

    CoInitialize(NULL);

    // Get a pointer to the IShellLink interface. 
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl); 
    if (SUCCEEDED(hres)) 
    { 
        IPersistFile* ppf; 
        
        // Get a pointer to the IPersistFile interface. 
        hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); 
        
        if (SUCCEEDED(hres)) 
        {
            WCHAR wsz[MAX_PATH]; 
            // Ensure that the string is Unicode. 
            MultiByteToWideChar(CP_ACP, 0, mPath, -1, wsz, MAX_PATH); 
 
            // Load the shortcut. 
            hres = ppf->Load(wsz, STGM_READ); 
            if (SUCCEEDED(hres)) 
            {
                wasSymlink = PR_TRUE;

                // Resolve the link. 
                hres = psl->Resolve(nsnull, SLR_NO_UI ); 
                if (SUCCEEDED(hres)) 
                { 
                    char szGotPath[MAX_PATH]; 
                    WIN32_FIND_DATA wfd; 

                    // Get the path to the link target. 
                    hres = psl->GetPath( szGotPath, MAX_PATH, &wfd, SLGP_UNCPRIORITY ); 

                    if (SUCCEEDED(hres))
                    {
                        // Here we modify the nsFileSpec;
                        mPath = szGotPath;
                        mError = NS_OK;
                    }
                } 
            }
            else {
                // It wasn't a shortcut. Oh well. Leave it like it was.
                hres = 0;
            }

            // Release the pointer to the IPersistFile interface. 
            ppf->Release(); 
        }
        // Release the pointer to the IShellLink interface. 
        psl->Release();
    }

    CoUninitialize();

    if (SUCCEEDED(hres))
        return NS_OK;

    return NS_FILE_FAILURE;
}
开发者ID:bringhurst,项目名称:vbox,代码行数:73,代码来源:nsFileSpecWin.cpp

示例15: ResolveIt

// Resolve a shortcut
// Source: https://msdn.microsoft.com/en-us/library/windows/desktop/bb776891%28v=vs.85%29.aspx
//
// ------> DO NOT FORGET TO CALL CoInitialize first
//
HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPWSTR lpszPath, int iPathBufferSize)
{ 
	IShellLink* psl; 
	
    HRESULT hres;
    WCHAR szGotPath[MAX_PATH]; 
    WCHAR szDescription[MAX_PATH]; 
    WIN32_FIND_DATA wfd; 
 
    *lpszPath = 0; // Assume failure 
 	
 	hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
	if(SUCCEEDED(hres))
    {
		IPersistFile* ppf; 
	
	    // Get a pointer to the IPersistFile interface. 
	    hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); 
	    
	    if (SUCCEEDED(hres)) 
	    { 
	        WCHAR wsz[MAX_PATH]; 
	
	        // Ensure that the string is Unicode. 
	        MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH); 
	
	        // Add code here to check return value from MultiByteWideChar 
	        // for success.
	
	        // Load the shortcut. 
	        hres = ppf->Load(wsz, STGM_READ); 
	        
	        if (SUCCEEDED(hres)) 
	        { 
	            // Resolve the link. 
	            hres = psl->Resolve(hwnd, SLR_NO_UI); 
	
	            if (SUCCEEDED(hres)) 
	            { 
	                // Get the path to the link target. 
	                hres = psl->GetPath((LPSTR)szGotPath, MAX_PATH, (WIN32_FIND_DATA*)&wfd, SLGP_SHORTPATH); 
	
	                if (SUCCEEDED(hres)) 
	                { 
	                    // Get the description of the target. 
	                    hres = psl->GetDescription((LPSTR)szDescription, MAX_PATH); 
	
	                    if (SUCCEEDED(hres)) 
	                    {
	                        hres = StringCbCopy((STRSAFE_LPSTR)lpszPath, iPathBufferSize, (STRSAFE_LPSTR)szGotPath);
	                        if (SUCCEEDED(hres))
	                        {
	                            // Handle success
	                        }
	                        else
	                        {
	                            // Handle the error
	                        }
	                    }
	                }
	            } 
	        } 
	
	        // Release the pointer to the IPersistFile interface. 
	        ppf->Release(); 
	    } 
	
	    // Release the pointer to the IShellLink interface. 
	    psl->Release(); 
	}
    return hres; 
}
开发者ID:nishanthkarthik,项目名称:graviton,代码行数:77,代码来源:main.cpp


注:本文中的IShellLink::Resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。