Esempio n. 1
0
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;
}
Esempio n. 2
0
BOOL NetPlaceConvertW(WCHAR *src, WCHAR *dst)
{
	IShellLinkW		*shellLink;
	IPersistFile	*persistFile;
	WCHAR	wDstBuf[MAX_PATH];
	WCHAR	*wSrc = src;
	WCHAR	*wDst = wDstBuf;
	BOOL	ret = FALSE;
	DWORD	attr, attr_mask = FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_READONLY;

	if ((attr = ::GetFileAttributesW(src)) == 0xffffffff || (attr & attr_mask) != attr_mask)
		return	FALSE;	// ディレクトリかつronly でないものは関係ない

	if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
				  IID_IShellLinkW, (void **)&shellLink))) {
		if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) {
			if (SUCCEEDED(persistFile->Load(wSrc, STGM_READ))) {
				if (SUCCEEDED(shellLink->GetPath(wDst, MAX_PATH, 0, SLGP_UNCPRIORITY))) {
					MakePathW(dst, wDstBuf, L"");
					ret = TRUE;
				}
			}
			persistFile->Release();
		}
		shellLink->Release();
	}

	return	ret;
}
Esempio n. 3
0
/*
	リンクの解決
	あらかじめ、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, MAX_PATH);
			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;
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
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);
}
Esempio n. 6
0
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; 
} 
Esempio n. 7
0
//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);
}
Esempio n. 8
0
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;
}
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;
}
Esempio n. 10
0
NS_IMETHODIMP
nsFileProtocolHandler::ReadURLFile(nsIFile* aFile, nsIURI** aURI)
{
// IUniformResourceLocator isn't supported by VC5 (bless its little heart)
#if _MSC_VER < 1200 || defined (WINCE)
    return NS_ERROR_NOT_AVAILABLE;
#else
    nsAutoString path;
    nsresult rv = aFile->GetPath(path);
    if (NS_FAILED(rv))
        return rv;

    if (path.Length() < 4)
        return NS_ERROR_NOT_AVAILABLE;
    if (!StringTail(path, 4).LowerCaseEqualsLiteral(".url"))
        return NS_ERROR_NOT_AVAILABLE;

    HRESULT result;

    rv = NS_ERROR_NOT_AVAILABLE;

    IUniformResourceLocator* urlLink = nsnull;
    result = ::CoCreateInstance(CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER,
                                IID_IUniformResourceLocator, (void**)&urlLink);
    if (SUCCEEDED(result) && urlLink) {
        IPersistFile* urlFile = nsnull;
        result = urlLink->QueryInterface(IID_IPersistFile, (void**)&urlFile);
        if (SUCCEEDED(result) && urlFile) {
            result = urlFile->Load(path.get(), STGM_READ);
            if (SUCCEEDED(result) ) {
                LPSTR lpTemp = nsnull;

                // The URL this method will give us back seems to be already
                // escaped. Hence, do not do escaping of our own.
                result = urlLink->GetURL(&lpTemp);
                if (SUCCEEDED(result) && lpTemp) {
                    rv = NS_NewURI(aURI, lpTemp);

                    // free the string that GetURL alloc'd
                    CoTaskMemFree(lpTemp);
                }
            }
            urlFile->Release();
        }
        urlLink->Release();
    }
    return rv;

#endif //_MSC_VER < 1200 || defined (WINCE)
}
Esempio n. 11
0
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;
}
Esempio n. 12
0
//获得快捷方式文件所指向的路径
//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;
}
Esempio n. 13
0
NTSTATUS GetPathFromLinkFile(PCWSTR LinkFilePath, PWCHAR FullPath, ULONG BufferCount)
{
    HRESULT         hResult;
    IShellLinkW    *ShellLink;
    IPersistFile   *PersistFile;

    CoInitialize(NULL);

    hResult = S_OK;
    ShellLink = NULL;
    PersistFile = NULL;

    LOOP_ONCE
    {
        hResult = CoCreateInstance(
                    CLSID_ShellLink,
                    NULL,
                    CLSCTX_INPROC_SERVER,
                    IID_IShellLinkW,
                    (PVOID *)&ShellLink
                  );
        if (FAILED(hResult))
            break;

        hResult = ShellLink->QueryInterface(IID_IPersistFile, (PVOID *)&PersistFile);
        if (FAILED(hResult))
            break;

        hResult = PersistFile->Load(LinkFilePath, 0);
        if (FAILED(hResult))
            break;

        hResult = ShellLink->GetPath(FullPath, BufferCount, NULL, SLGP_UNCPRIORITY);
    }

    if (PersistFile != NULL)
        PersistFile->Release();

    if (ShellLink != NULL)
        ShellLink->Release();

    CoUninitialize();

    return hResult;
}
Esempio n. 14
0
//-----------------------------------------------------------------------------
// Purpose: retrieves shortcut (.lnk) information
//-----------------------------------------------------------------------------
bool CSystem::GetShortcutTarget(const char *linkFileName, char *targetPath, char *arguments, int destBufferSizes)
{
#ifndef _X360
	char temp[MAX_PATH];
	strcpy(temp, linkFileName);
	strlwr(temp);

	targetPath[0] = 0;
	arguments[0] = 0;

	// Create the ShellLink object
	IShellLink *psl;
	HRESULT hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl);
	if (SUCCEEDED(hres))
	{
		IPersistFile *ppf;
		// Bind the ShellLink object to the Persistent File
		hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
		if (SUCCEEDED(hres))
		{
			wchar_t wsz[MAX_PATH];
			// Get a UNICODE wide string wsz from the link path
			MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, temp, -1, wsz, MAX_PATH);
			
			// Read the link into the persistent file
			hres = ppf->Load(wsz, 0);
			
			if (SUCCEEDED(hres))
			{
				//Read the target information from the link object
				//UNC paths are supported (SLGP_UNCPRIORITY)
				psl->GetPath(targetPath, destBufferSizes, NULL, SLGP_UNCPRIORITY);

				//Read the arguments from the link object
				psl->GetArguments(arguments, destBufferSizes);
			}
			ppf->Release();
		}
		psl->Release();
	}
	return (targetPath[0] != 0);
#else
	return false;
#endif
}
Esempio n. 15
0
//----------------------------------------------------------------------------------------
PRBool nsFileSpec::IsSymlink() const
//----------------------------------------------------------------------------------------
{
    HRESULT hres; 
    IShellLink* psl; 
    
    PRBool isSymlink = PR_FALSE;
    
    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)) 
            {
                isSymlink = PR_TRUE;
            }
            
            // Release the pointer to the IPersistFile interface. 
            ppf->Release(); 
        }
        
        // Release the pointer to the IShellLink interface. 
        psl->Release();
    }

    CoUninitialize();

    return isSymlink;
}
Esempio n. 16
0
//-----------------------------------------------------------------------------
// Purpose: sets shortcut (.lnk) information
//-----------------------------------------------------------------------------
bool CSystem::ModifyShortcutTarget(const char *linkFileName, const char *targetPath, const char *arguments, const char *workingDirectory)
{
#ifndef _X360
	bool bSuccess = false;
	char temp[MAX_PATH];
	strcpy(temp, linkFileName);
	strlwr(temp);

	// Create the ShellLink object
	IShellLink *psl;
	HRESULT hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl);
	if (SUCCEEDED(hres))
	{
		IPersistFile *ppf;
		// Bind the ShellLink object to the Persistent File
		hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
		if (SUCCEEDED(hres))
		{
			wchar_t wsz[MAX_PATH];
			// Get a UNICODE wide string wsz from the link path
			MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, temp, -1, wsz, MAX_PATH);
			
			// Read the link into the persistent file
			hres = ppf->Load(wsz, 0);
			
			if (SUCCEEDED(hres))
			{ 
				// Set the target information from the link object
				psl->SetPath(targetPath);
				psl->SetArguments(arguments);
				psl->SetWorkingDirectory(workingDirectory);
				bSuccess = true;
				ppf->Save(wsz, TRUE);
			}
			ppf->Release();
		}
		psl->Release();
	}
	return bSuccess;
#else
	return false;
#endif
}
Esempio n. 17
0
//-----------------------------------------------------------------------------
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;	
}
Esempio n. 18
0
HRESULT ShellFunctions::GetShortcutTarget(LPCSTR pszShortcutFile,LPSTR pszTarget,DWORD nBufSize)
{
	HRESULT hres;  
	IShellLink* psl;
	
	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->GetPath(pszTarget,nBufSize,NULL,0);
			ppf->Release();
		}
		psl->Release();  
	}
	return hres;
}
Esempio n. 19
0
BOOL ReadLinkW(WCHAR *src, WCHAR *dest, WCHAR *arg)
{
	IShellLinkW		*shellLink;		// 実際は IShellLinkA or IShellLinkW
	IPersistFile	*persistFile;
	BOOL			ret = FALSE;

	if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW,
			(void **)&shellLink))) {
		if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) {
			if (SUCCEEDED(persistFile->Load((WCHAR *)src, STGM_READ))) {
				if (SUCCEEDED(shellLink->GetPath(dest, MAX_PATH, NULL, 0))) {
					if (arg) {
						shellLink->GetArguments(arg, MAX_PATH);
					}
					ret = TRUE;
				}
			}
			persistFile->Release();
		}
		shellLink->Release();
	}
	return	ret;
}
Esempio n. 20
0
long GetURLShortCut( char *linkpath, char *newpath )
{
	HRESULT hres;
	IUniformResourceLocator *pHook;
    
	CoInitialize(NULL);
	hres = CoCreateInstance(CLSID_InternetShortcut, NULL, 
        CLSCTX_INPROC_SERVER, IID_IUniformResourceLocator,(void**)&pHook); 
    if (SUCCEEDED(hres)) {
		IPersistFile *ppf;
		IShellLink *psl;

		hres = pHook->QueryInterface (IID_IPersistFile, (void **)&ppf);		//IID_IPersistFile
		hres = pHook->QueryInterface (IID_IShellLink, (void **)&psl);
		if (SUCCEEDED(hres)) { 
            WCHAR wsz[MAX_PATH];
			char *lpsz;

            MultiByteToWideChar(CP_ACP, 0, linkpath, -1, wsz,  MAX_PATH);              // Load the shortcut. 
			hres = ppf->Load (wsz, TRUE);
			if (SUCCEEDED(hres)) { 
				pHook->GetURL(&lpsz);
				if ( lpsz )
					strcpy( newpath, lpsz );
			}
	        psl->Release();
            ppf->Release();
			if(!SUCCEEDED(hres))
				return false;
		} else
			return false;
		pHook->Release ();
	} else
		return false;
	CoUninitialize();
	return true;
}
Esempio n. 21
0
BOOL NetPlaceConvertV(void *src, void *dst)
{
	IShellLink		*shellLink;		// VC4 には IShellLink ANSI 版しか定義がないための暫定処置
	IPersistFile	*persistFile;	// (実際は NT系では IShellLinkW を呼び出し)
	WCHAR	wSrcBuf[MAX_PATH], wDstBuf[MAX_PATH];
	WCHAR	*wSrc = IS_WINNT_V ? (WCHAR *)src : wSrcBuf;
	WCHAR	*wDst = IS_WINNT_V ? wDstBuf : (WCHAR *)dst;
	BOOL	ret = FALSE;
	DWORD	attr, attr_mask = FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_READONLY;

	if (SHGetPathFromIDListV == NULL)	// NT4.0 系は無視
		return	FALSE;

	if ((attr = GetFileAttributesV(src)) == 0xffffffff || (attr & attr_mask) != attr_mask)
		return	FALSE;	// ディレクトリかつronly でないものは関係ない

	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)
				AtoW((char *)src, wSrc, MAX_PATH);

			if (SUCCEEDED(persistFile->Load(wSrc, STGM_READ))) {
				if (SUCCEEDED(shellLink->GetPath((char *)wDst, MAX_PATH, 0, SLGP_UNCPRIORITY))) {
					if (!IS_WINNT_V)
						WtoA(wDst, (char *)wDstBuf, MAX_PATH);
					MakePathV(dst, wDstBuf, EMPTY_STR_V);
					ret = TRUE;
				}
			}
			persistFile->Release();
		}
		shellLink->Release();
	}

	return	ret;
}
Esempio n. 22
0
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;
}
// @pymethod |PyIPersistFile|Load|Opens the specified file and initializes an object from the file contents.
PyObject *PyIPersistFile::Load(PyObject *self, PyObject *args)
{
	IPersistFile *pIPF = GetI(self);
	if ( pIPF == NULL )
		return NULL;
	// @pyparm str|FileName||Absolute path of the file to open
	// @pyparm int|Mode|STGM_READ|Specifies the access mode from the STGM enumeration.
	PyObject *obFileName;
	TmpWCHAR FileName;
	DWORD dwMode = STGM_READ;
	if ( !PyArg_ParseTuple(args, "O|l:Load", &obFileName, &dwMode) )
		return NULL;
	if (!PyWinObject_AsWCHAR(obFileName, &FileName))
		return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIPF->Load(FileName, dwMode );
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIPF, IID_IPersistFile);
	Py_INCREF(Py_None);
	return Py_None;
}
Esempio n. 24
0
//----------------------------------------------------------------------------------------
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;
}
Esempio n. 25
0
bool FileSystemManager::getShortcutTarget(QString shortcutFileName, QString * targetOut, QString * argsOut, QString * workingDirOut)
{
	assert(targetOut);

	// return true if _any_ of the attributes can be resolved

	bool targetResolved = false;
	bool result = false;
	IShellLink * psl = NULL; 

	// Accounting for the newer "Advertised Shortcuts" which refer to MSI operations which may pre-empt the 
	// launching of the specified shortcut
	DWORD targetPathLen = MAX_PATH;
	TCHAR targetPath[MAX_PATH];
	TCHAR productCode[MAX_PATH];
	TCHAR featureId[MAX_PATH];
	TCHAR componentCode[MAX_PATH];
	if (pfnMsiGetShortcutTarget && pfnMsiGetComponentPath)
	{
		if (ERROR_SUCCESS == pfnMsiGetShortcutTarget((LPCTSTR) shortcutFileName.utf16(), productCode, featureId, componentCode)) 
		{
			if (INSTALLSTATE_LOCAL == pfnMsiGetComponentPath(productCode, componentCode, targetPath, &targetPathLen))
			{
				*targetOut = QString::fromUtf16((const ushort *) targetPath);
				targetResolved = true;
				result = true;
			}
		}
	}

	// Get a pointer to the IShellLink interface. 
	TCHAR args[MAX_PATH];
	TCHAR workingDir[MAX_PATH];

	HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl); 
	if (SUCCEEDED(hres)) 
	{ 
		IPersistFile * ppf = NULL; 

		// Get a pointer to the IPersistFile interface. 
		if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (LPVOID *) &ppf))) 
		{ 
			// Load the shortcut. 
			if (SUCCEEDED(ppf->Load((LPCOLESTR) shortcutFileName.utf16(), STGM_READ))) 
			{ 
				// Resolve the link. 
				if (SUCCEEDED(psl->Resolve(winOS->GetWindowsHandle(), SLR_NOUPDATE | SLR_NO_UI))) 
				{ 
					// Get the path to the link target. 
					if (!targetResolved && SUCCEEDED(psl->GetPath(targetPath, MAX_PATH, NULL, 0))) 
					{
						*targetOut = QString::fromUtf16((const ushort *) targetPath);
						result = true;
					}
					if (argsOut && SUCCEEDED(psl->GetArguments(args, MAX_PATH)))
					{
						*argsOut = QString::fromUtf16((const ushort *) args);
						result = true;
					}
					if (workingDirOut && SUCCEEDED(psl->GetWorkingDirectory(workingDir, MAX_PATH)))
					{
						*workingDirOut = QString::fromUtf16((const ushort *) workingDir);
						result = true;
					}
				} 
			} 

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

		// Release the pointer to the IShellLink interface. 
		psl->Release(); 
	} 
	return result;
}
Esempio n. 26
0
BOOL CInstall::CreateShellLink(LPCSTR description, LPCSTR program,
                               LPCSTR arguments, LPCSTR icon, int nIconIndex)
{
    HRESULT hres;
    IShellLink* psl;
    CHAR szLink[MAXSTR];
    strcpy(szLink, m_szPrograms);
    strcat(szLink, "\\");
    strcat(szLink, m_szTargetGroup);
    strcat(szLink, "\\");
    strcat(szLink, description);
    strcat(szLink, ".LNK");
    AddMessage("Adding shell link\n   ");
    AddMessage(szLink);
    AddMessage("\n");

    // Ensure string is UNICODE.
    WCHAR wsz[MAX_PATH];
    MultiByteToWideChar(CP_ACP, 0, szLink, -1, wsz, MAX_PATH);

    // Save old shell link

    // Get a pointer to the IShellLink interface.
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                            IID_IShellLink, (void **)&psl);
    if (SUCCEEDED(hres))    {
        IPersistFile* ppf;
        // Query IShellLink for the IPersistFile interface.
        hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
        if (SUCCEEDED(hres))       {
            // Load the shell link.
            hres = ppf->Load(wsz, STGM_READ);
            if (SUCCEEDED(hres)) {
                // Resolve the link.
                hres = psl->Resolve(HWND_DESKTOP, SLR_ANY_MATCH);
                if (SUCCEEDED(hres)) {
                    // found it, so save details
                    CHAR szTemp[MAXSTR];
                    WIN32_FIND_DATA wfd;
                    int i;


                    fprintf(m_fLogOld, "Name=%s\n", szLink);
                    hres = psl->GetPath(szTemp, MAXSTR, (WIN32_FIND_DATA *)&wfd,
                                        SLGP_SHORTPATH );
                    if (SUCCEEDED(hres))
                        fprintf(m_fLogOld, "Path=%s\n", szTemp);
                    hres = psl->GetDescription(szTemp, MAXSTR);
                    if (SUCCEEDED(hres))
                        fprintf(m_fLogOld, "Description=%s\n", szTemp);
                    hres = psl->GetArguments(szTemp, MAXSTR);
                    if (SUCCEEDED(hres) && (szTemp[0] != '\0'))
                        fprintf(m_fLogOld, "Arguments=%s\n", szTemp);
                    hres = psl->GetWorkingDirectory(szTemp, MAXSTR);
                    if (SUCCEEDED(hres) && (szTemp[0] != '\0'))
                        fprintf(m_fLogOld, "Directory=%s\n", szTemp);
                    hres = psl->GetIconLocation(szTemp, MAXSTR, &i);
                    if (SUCCEEDED(hres) && (szTemp[0] != '\0')) {
                        fprintf(m_fLogOld, "IconLocation=%s\n", szTemp);
                        fprintf(m_fLogOld, "IconIndex=%d\n", i);
                    }
                    fprintf(m_fLogOld, "\n");
                }
            }
            // Release pointer to IPersistFile.
            ppf->Release();
        }
        // Release pointer to IShellLink.
        psl->Release();
    }


    // Save new shell link

    // Get a pointer to the IShellLink interface.
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                            IID_IShellLink, (void **)&psl);
    if (SUCCEEDED(hres))    {
        IPersistFile* ppf;
        // Query IShellLink for the IPersistFile interface for
        // saving the shell link in persistent storage.
        hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
        if (SUCCEEDED(hres)) {
            fprintf(m_fLogNew, "Name=%s\n", szLink);

            // Set the path to the shell link target.
            hres = psl->SetPath(program);
            if (!SUCCEEDED(hres))
                AddMessage("SetPath failed!");
            fprintf(m_fLogNew, "Path=%s\n", program);
            // Set the description of the shell link.
            hres = psl->SetDescription(description);
            if (!SUCCEEDED(hres))
                AddMessage("SetDescription failed!");
            fprintf(m_fLogNew, "Description=%s\n", description);
            if (arguments != (LPCSTR)NULL) {
                // Set the arguments of the shell link target.
                hres = psl->SetArguments(arguments);
                if (!SUCCEEDED(hres))
                    AddMessage("SetArguments failed!");
                fprintf(m_fLogNew, "Arguments=%s\n", arguments);
            }
            if (icon != (LPCSTR)NULL) {
                // Set the arguments of the shell link target.
                hres = psl->SetIconLocation(icon, nIconIndex);
                if (!SUCCEEDED(hres))
                    AddMessage("SetIconLocation failed!");
                fprintf(m_fLogNew, "IconLocation=%s\n", icon);
                fprintf(m_fLogNew, "IconIndex=%d\n", nIconIndex);
            }

            // Save the link via the IPersistFile::Save method.
            hres = ppf->Save(wsz, TRUE);
            // Release pointer to IPersistFile.
            ppf->Release();
        }
        // Release pointer to IShellLink.
        psl->Release();
        fprintf(m_fLogNew, "\n");
    }

    return (hres == 0);
}
Esempio n. 27
0
/*
 * Class:     sun_awt_shell_Win32ShellFolder2
 * Method:    getLinkLocation
 * Signature: (JJZ)J;
 */
JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_getLinkLocation
    (JNIEnv* env, jclass cls, jlong parentIShellFolder, jlong relativePIDL, jboolean resolve)
{
    HRESULT hres;
    STRRET strret;
    OLECHAR olePath[MAX_PATH]; // wide-char version of path name
    LPWSTR wstr;

    IShellFolder* pParent = (IShellFolder*)parentIShellFolder;
    if (pParent == NULL) {
        return NULL;
    }

    LPITEMIDLIST pidl = (LPITEMIDLIST)relativePIDL;
    if (pidl == NULL) {
        return NULL;
    }

    hres = pParent->GetDisplayNameOf(pidl, SHGDN_NORMAL | SHGDN_FORPARSING, &strret);
    if (FAILED(hres)) {
        return NULL;
    }

    switch (strret.uType) {
      case STRRET_CSTR :
        // IShellFolder::ParseDisplayName requires the path name in Unicode.
        MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, strret.cStr, -1, olePath, MAX_PATH);
        wstr = olePath;
        break;

      case STRRET_OFFSET :
        MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (CHAR *)pidl + strret.uOffset, -1, olePath, MAX_PATH);
        wstr = olePath;
        break;

      case STRRET_WSTR :
        wstr = strret.pOleStr;
        break;

      default:
        return NULL;
    }

    IShellLinkW* psl;
    hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID *)&psl);
    if (SUCCEEDED(hres)) {
        IPersistFile* ppf;
        hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
        if (SUCCEEDED(hres)) {
            hres = ppf->Load(wstr, STGM_READ);
            if (SUCCEEDED(hres)) {
                if (resolve) {
                    hres = psl->Resolve(NULL, 0);
                    // Ignore failure
                }
                pidl = (LPITEMIDLIST)NULL;
                hres = psl->GetIDList(&pidl);
            }
            ppf->Release();
        }
        psl->Release();
    }

    if (strret.uType == STRRET_WSTR) {
        CoTaskMemFree(strret.pOleStr);
    }
    if (SUCCEEDED(hres)) {
        return (jlong)pidl;
    } else {
        return 0;
    }
}
Esempio n. 28
0
CString CDirectoriesPropertyPage::ExpandShortcut(CString& csFilename) const
{
	USES_CONVERSION;		// For T2COLE() below
	CString csExpandedFile;

	//
    // Make sure we have a path
	//
	if(csFilename.IsEmpty())
	{
		ASSERT(FALSE);
		return csExpandedFile;
	}

	//
    // Get a pointer to the IShellLink interface
	//
    HRESULT hr;
    IShellLink* pIShellLink;

    hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
							IID_IShellLink, (LPVOID*) &pIShellLink);

    if (SUCCEEDED(hr))
    {

		//
        // Get a pointer to the persist file interface
		//
		IPersistFile* pIPersistFile;
        hr = pIShellLink->QueryInterface(IID_IPersistFile, (LPVOID*) &pIPersistFile);

        if (SUCCEEDED(hr))
        {
			//
            // Load the shortcut and resolve the path
			//
            // IPersistFile::Load() expects a UNICODE string
			// so we're using the T2COLE macro for the conversion
			//
			// For more info, check out MFC Technical note TN059
			// (these macros are also supported in ATL and are
			// so much better than the ::MultiByteToWideChar() family)
			//
            hr = pIPersistFile->Load(T2COLE(csFilename), STGM_READ);
			
			if (SUCCEEDED(hr))
			{
				WIN32_FIND_DATA wfd;
				hr = pIShellLink->GetPath(csExpandedFile.GetBuffer(MAX_PATH),
										  MAX_PATH,
										  &wfd,
										  SLGP_UNCPRIORITY);

				csExpandedFile.ReleaseBuffer(-1);
            }
            pIPersistFile->Release();
        }
        pIShellLink->Release();
    }

    return csExpandedFile;
}
Esempio n. 29
0
STDMETHODIMP CAVIFileRemote::Open(LPCSTR szFile, UINT mode, LPCOLESTR lpszFileName) {
	HMMIO hmmio = NULL;
	MMCKINFO mmiriff, mmi;
	MMRESULT mmerr;
	HRESULT final = S_OK;

	_RPT2(0,"CAVIFileRemote::Open(\"%s\", %08lx)\n", szFile, mode);

	if (pafTunnel) {
		pafTunnel->Release();
		pafTunnel = NULL;
	}

	if (mode & (OF_CREATE|OF_WRITE)) {
		IPersistFile *ppf;

		if (FAILED(CoCreateInstance(CLSID_AVIFile, NULL, CLSCTX_INPROC_SERVER, another_IID_IAVIFile, (void **)&pafTunnel)))
			return (HRESULT)E_FAIL;

		if (FAILED(pafTunnel->QueryInterface(IID_IPersistFile, (void **)&ppf)))
			return (HRESULT)E_FAIL;

		HRESULT hr = ppf->Load(lpszFileName, mode);

		ppf->Release();

		return hr;
	}

	if (!(hmmio = mmioOpen((char *)szFile, NULL, MMIO_READ)))
		return E_FAIL;

	_RPT0(0,"File opened.\n");

	// RIFF <size> VDRM { PATH <remote-path> }

	try {
		char buf[16];

		_RPT0(0,"Checking for Avisynth signature...\n");

		if (16==mmioRead(hmmio, buf, 16)) {
			buf[9] = 0;
			if (!_stricmp(buf, "#avisynth")) {

				mmioClose(hmmio, 0);

				// Hand it off to the Avisynth handler.

				IPersistFile *ppf;

				// Okay, it's not one of our files.  Now try passing it off
				// to the regular AVI handler!

				_RPT0(0,"Attempt avisynth tunnel create\n");

				if (FAILED(CoCreateInstance(CLSID_Avisynth, NULL, CLSCTX_INPROC_SERVER, another_IID_IAVIFile, (void **)&pafTunnel)))
					return (HRESULT)E_FAIL;

				_RPT0(0,"Attempt avisynth tunnel query -> IPersistFile\n");

				if (FAILED(pafTunnel->QueryInterface(IID_IPersistFile, (void **)&ppf)))
					return (HRESULT)E_FAIL;

				_RPT0(0,"Attempt avisynth tunnel load\n");

				HRESULT hr = ppf->Load(lpszFileName, mode);

				ppf->Release();

				return hr;
			}
		}

		mmioSeek(hmmio, 0, SEEK_SET);

		_RPT0(0,"Attempting to find 'VDRM'...\n");

		mmiriff.fccType = 'MRDV';
		mmerr = mmioDescend(hmmio, &mmiriff, NULL, MMIO_FINDRIFF);
		if (mmerr == MMIOERR_CHUNKNOTFOUND) {
			IPersistFile *ppf;

			mmioClose(hmmio, 0);

			// Okay, it's not one of our files.  Now try passing it off
			// to the regular AVI handler!

			_RPT0(0,"Attempt tunnel create\n");

			if (FAILED(CoCreateInstance(CLSID_AVIFile, NULL, CLSCTX_INPROC_SERVER, another_IID_IAVIFile, (void **)&pafTunnel)))
				return (HRESULT)E_FAIL;

			_RPT0(0,"Attempt tunnel query -> IPersistFile\n");

			if (FAILED(pafTunnel->QueryInterface(IID_IPersistFile, (void **)&ppf)))
				return (HRESULT)E_FAIL;

			_RPT0(0,"Attempt tunnel load\n");

			HRESULT hr = ppf->Load(lpszFileName, mode);

			ppf->Release();

			return hr;
		}

		else if (mmerr != MMSYSERR_NOERROR) throw (HRESULT)E_FAIL;

		_RPT0(0,"Attempting to find 'PATH'...\n");
		mmi.ckid = 'HTAP';
		mmerr = mmioDescend(hmmio, &mmi, &mmiriff, MMIO_FINDCHUNK);
		if (mmerr == MMIOERR_CHUNKNOTFOUND) throw (HRESULT)E_FAIL;
		else if (mmerr != MMSYSERR_NOERROR) throw (HRESULT)E_FAIL;

		_RPT0(0,"Allocate path memory...\n");
		if (!(szPath = new char[mmi.cksize+1]))
			throw (HRESULT)E_OUTOFMEMORY;

		szPath[mmi.cksize]=0;

		_RPT0(0,"Read in path...\n");

		if ((LONG)mmi.cksize != mmioRead(hmmio, szPath, mmi.cksize))
			throw (HRESULT)E_FAIL;

		_RPT1(0,"File parsed, remote-path: [%s]\n", szPath);

		// now attempt to open the link

		ivdsl = GetDubServerInterface();
		if (!ivdsl) throw (HRESULT)E_FAIL;

		_RPT0(0,"Have dub server interface.\n");

		ivdac = ivdsl->FrameServerConnect(szPath);
		if (!ivdac) throw (HRESULT)E_FAIL;

		// retrieve streaminfo and format information

		_RPT0(0,"Connected to frameserver.\n");

		fHasAudio = ivdac->hasAudio();

		_RPT0(0,"Reading video stream info...\n");

		if (!ivdac->readStreamInfo(&vStreamInfo, FALSE, &vSampleFirst, &vSampleLast))
			throw (HRESULT)E_FAIL;

		_RPT0(0,"Reading video format length...\n");

		if ((vFormatLen = ivdac->readFormat(NULL, FALSE))<=0)
			throw (HRESULT)E_FAIL;

		_RPT1(0,"Allocating video format (%ld bytes)...\n", vFormatLen);

		if (!(vFormat = (BITMAPINFOHEADER *)malloc(vFormatLen)))
			throw (HRESULT)E_OUTOFMEMORY;

		_RPT0(0,"Reading video format...\n");

		if (ivdac->readFormat(vFormat, FALSE)<=0)
			throw (HRESULT)E_FAIL;

		if (fHasAudio) {
			_RPT0(0,"Reading audio stream info...\n");

			if (!ivdac->readStreamInfo(&aStreamInfo, TRUE, &aSampleFirst, &aSampleLast))
				throw (HRESULT)E_FAIL;

			_RPT0(0,"Reading audio format length...\n");

			if ((aFormatLen = ivdac->readFormat(NULL, TRUE))<=0)
				throw (HRESULT)E_FAIL;

			_RPT1(0,"Allocating audio format (%ld bytes)...\n", aFormatLen);

			if (!(aFormat = (WAVEFORMATEX *)malloc(aFormatLen)))
				throw (HRESULT)E_OUTOFMEMORY;

			_RPT0(0,"Reading audio format...\n");

			if (ivdac->readFormat(aFormat, TRUE)<=0)
				throw (HRESULT)E_FAIL;
		}

	} catch(HRESULT res) {
		_RPT0(0,"*** failed!\n");

		final = res;
	}
Esempio n. 30
0
/*! ショートカット(.lnk)の解決
	@date 2009.01.08 ryoji CoInitialize/CoUninitializeを削除(WinMainにOleInitialize/OleUninitializeを追加)
*/
BOOL ResolveShortcutLink( HWND hwnd, LPCTSTR lpszLinkFile, LPTSTR lpszPath )
{
	BOOL			bRes;
	HRESULT			hRes;
	IShellLink*		pIShellLink;
	IPersistFile*	pIPersistFile;
	WIN32_FIND_DATA	wfd;
	/* 初期化 */
	pIShellLink = NULL;
	pIPersistFile = NULL;
	*lpszPath = 0; // assume failure
	bRes = FALSE;

// 2009.01.08 ryoji CoInitializeを削除(WinMainにOleInitialize追加)

	// Get a pointer to the IShellLink interface.
//	hRes = 0;
	TCHAR szAbsLongPath[_MAX_PATH];
	if( ! ::GetLongFileName( lpszLinkFile, szAbsLongPath ) ){
		return FALSE;
	}

	// 2010.08.28 DLL インジェクション対策としてEXEのフォルダに移動する
	CCurrentDirectoryBackupPoint dirBack;
	ChangeCurrentDirectoryToExeDir();

	if( SUCCEEDED( hRes = ::CoCreateInstance( CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&pIShellLink ) ) ){
		// Get a pointer to the IPersistFile interface.
		if( SUCCEEDED(hRes = pIShellLink->QueryInterface( IID_IPersistFile, (void**)&pIPersistFile ) ) ){
			// Ensure that the string is Unicode.
			WCHAR wsz[MAX_PATH];
			_tcstowcs(wsz, szAbsLongPath, _countof(wsz));
//			MultiByteToWideChar( CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH );
			// Load the shortcut.
			if( SUCCEEDED(hRes = pIPersistFile->Load( wsz, STGM_READ ) ) ){
				// Resolve the link.
				if( SUCCEEDED( hRes = pIShellLink->Resolve(hwnd, SLR_ANY_MATCH ) ) ){
					// Get the path to the link target.
					TCHAR szGotPath[MAX_PATH];
					szGotPath[0] = _T('\0');
					if( SUCCEEDED( hRes = pIShellLink->GetPath(szGotPath, MAX_PATH, &wfd, SLGP_SHORTPATH ) ) ){
						// Get the description of the target.
						TCHAR szDescription[MAX_PATH];
						if( SUCCEEDED(hRes = pIShellLink->GetDescription(szDescription, MAX_PATH ) ) ){
							if( _T('\0') != szGotPath[0] ){
								/* 正常終了 */
								_tcscpy_s( lpszPath, _MAX_PATH, szGotPath );
								bRes = TRUE;
							}
						}
					}
				}
			}
		}
	}
	// Release the pointer to the IPersistFile interface.
	if( NULL != pIPersistFile ){
		pIPersistFile->Release();
		pIPersistFile = NULL;
	}
	// Release the pointer to the IShellLink interface.
	if( NULL != pIShellLink ){
		pIShellLink->Release();
		pIShellLink = NULL;
	}
// 2009.01.08 ryoji CoUninitializeを削除(WinMainにOleUninitialize追加)
	return bRes;
}