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


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

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


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

示例1: SetStartOnSystemStartup

bool SetStartOnSystemStartup(bool fAutoStart)
{
    // If the shortcut exists already, remove it for updating
    boost::filesystem::remove(StartupShortcutPath());

    if (fAutoStart)
    {
        CoInitialize(NULL);

        // Get a pointer to the IShellLink interface.
        IShellLink* psl = NULL;
        HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,
                                CLSCTX_INPROC_SERVER, IID_IShellLink,
                                reinterpret_cast<void**>(&psl));

        if (SUCCEEDED(hres))
        {
            // Get the current executable path
            TCHAR pszExePath[MAX_PATH];
            GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));

            TCHAR pszArgs[5] = TEXT("-min");

            // Set the path to the shortcut target
            psl->SetPath(pszExePath);
            PathRemoveFileSpec(pszExePath);
            psl->SetWorkingDirectory(pszExePath);
            psl->SetShowCmd(SW_SHOWMINNOACTIVE);
            psl->SetArguments(pszArgs);

            // Query IShellLink for the IPersistFile interface for
            // saving the shortcut in persistent storage.
            IPersistFile* ppf = NULL;
            hres = psl->QueryInterface(IID_IPersistFile,
                                       reinterpret_cast<void**>(&ppf));
            if (SUCCEEDED(hres))
            {
                WCHAR pwsz[MAX_PATH];
                // Ensure that the string is ANSI.
                MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().string().c_str(), -1, pwsz, MAX_PATH);
                // Save the link by calling IPersistFile::Save.
                hres = ppf->Save(pwsz, TRUE);
                ppf->Release();
                psl->Release();
                CoUninitialize();
                return true;
            }
            psl->Release();
        }
        CoUninitialize();
        return false;
    }
    return true;
}
开发者ID:ODNT,项目名称:ODNT,代码行数:54,代码来源:guiutil.cpp

示例2: CreateShortcut

// ショートカット作成
BOOL CreateShortcut ( LPCTSTR pszTargetPath /* ターゲットパス */,
    LPCTSTR pszArguments /* 引数 */,
    LPCTSTR pszWorkPath /* 作業ディレクトリ */,
    int nCmdShow /* ShowWindowの引数 */,
    LPCSTR pszShortcutPath /* ショートカットファイル(*.lnk)のパス */ )
{
    IShellLink *psl = NULL;
    IPersistFile *ppf = NULL;
    enum
    {
        MY_MAX_PATH = 65536
    };
    TCHAR wcLink[ MY_MAX_PATH ]=_T("");

    // IShellLinkインターフェースの作成
    HRESULT result = CoCreateInstance( CLSID_ShellLink, NULL,CLSCTX_INPROC_SERVER, IID_IShellLink, ( void ** ) &psl);
	if(FAILED(result))
    {
		return result;
	}

    // 設定
    psl->SetPath ( pszTargetPath );
    psl->SetArguments ( pszArguments );
    psl->SetWorkingDirectory ( pszWorkPath );
    psl->SetShowCmd ( nCmdShow );

    // IPersistFileインターフェースの作成
    if ( FAILED ( psl->QueryInterface ( IID_IPersistFile, ( void ** ) &ppf ) ) )
    {
        psl->Release ();
        return FALSE;
    }
    
    // lpszLinkをWCHAR型に変換
    MultiByteToWideChar ( CP_ACP, 0, pszShortcutPath, -1, wcLink, MY_MAX_PATH );
    if ( FAILED ( ppf->Save ( wcLink, TRUE ) ) )
    {
        ppf->Release ();
        return FALSE;
    }

	result = ppf->Save((LPCOLESTR)pszShortcutPath,TRUE);
	
    // 解放
    ppf->Release ();
    psl->Release ();

    return TRUE;
}
开发者ID:kimoto,项目名称:mwheel_plus,代码行数:51,代码来源:Util.cpp

示例3: createLinks

void createLinks(const std::string name, const std::string &exe)
{
  CoInitialize(NULL);
  HRESULT res;
  IShellLink *lnk = NULL;

  res = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                         IID_IShellLink, reinterpret_cast<void**>(&lnk));
  if(!SUCCEEDED(res))
    fail("Couldn't create shortcut links");

  lnk->SetPath(exe.c_str());
  lnk->SetDescription(name.c_str());
  //lnk->SetIconLocation("where", 0);

  IPersistFile *pf = NULL;
  res = lnk->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&pf));
  if(!SUCCEEDED(res))
    {
      lnk->Release();
      fail("Couldn't create shortcut links");
    }

  // Use this for links you don't want to highlight, ie. everything
  // except the main program link. May need some rewriting.
  /*
  PROPVARIANT pvar;
  pvar.vt = VT_BOOL;
  pvar.boolVal = VARIANT_TRUE;
  pf->SetValue(PKEY_AppUserModel_ExcludeFromShowInNewInstall, pvar);
  */

  std::string lname = name + ".lnk";

  // Save desktop link
  fs::path link = getPathCSIDL(CSIDL_DESKTOPDIRECTORY) / lname;
  pf->Save(toWide(link.string()), TRUE);

  // Create start menu directory
  link = getPathCSIDL(CSIDL_PROGRAMS) / name;
  fs::create_directories(link);

  // Save the start menu link
  link /= lname;
  pf->Save(toWide(link.string()), TRUE);

  pf->Release();
  lnk->Release();
}
开发者ID:cooljeanius,项目名称:Tiggit,代码行数:49,代码来源:win32_setup.cpp

示例4: CreateLinkToFile

HRESULT CreateLinkToFile(TCHAR *PathToFile,TCHAR *PathToLink,TCHAR *LinkDescription)
{
	IShellLink		*pShellLink = NULL;
	IPersistFile	*pPersistFile = NULL;
	WCHAR			PathToLinkW[MAX_PATH];
	HRESULT			hr;

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

	if(SUCCEEDED(hr))
	{
		pShellLink->SetPath(PathToFile);
		pShellLink->SetDescription(LinkDescription);

		hr = pShellLink->QueryInterface(IID_IPersistFile,(LPVOID*)&pPersistFile);

		if(SUCCEEDED(hr))
		{
			#ifndef UNICODE
			MultiByteToWideChar(CP_ACP,0,PathToLink,-1,PathToLinkW,MAX_PATH);
			#else
			StringCchCopy(PathToLinkW,SIZEOF_ARRAY(PathToLinkW),PathToLink);
			#endif

			pPersistFile->Save(PathToLinkW,TRUE);

			pPersistFile->Release();
		}

		pShellLink->Release();
	}

	return hr;
}
开发者ID:yellowbigbird,项目名称:bird-self-lib,代码行数:35,代码来源:FileOperations.c

示例5: 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;
}
开发者ID:rauls,项目名称:iReporter,代码行数:31,代码来源:createshortcuts.cpp

示例6: my_createshortcut

// http://msdn.microsoft.com/en-us/library/aa969393.aspx
bool my_createshortcut(const TCHAR *source, const TCHAR *target, const TCHAR *description) 
{ 
    HRESULT hres; 
    IShellLink* psl;
	TCHAR tmp[MAX_DPATH];
 
    // Get a pointer to the IShellLink interface. It is assumed that CoInitialize
    // has already been called.
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); 
    if (SUCCEEDED(hres)) 
    { 
        IPersistFile* ppf; 
 
        // Set the path to the shortcut target and add the description. 
        psl->SetPath(target); 
        psl->SetDescription(description); 
 
        // Query IShellLink for the IPersistFile interface, used for saving the 
        // shortcut in persistent storage. 
        hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); 
 
        if (SUCCEEDED(hres)) 
        { 
            // Save the link by calling IPersistFile::Save. 
			_tcscpy (tmp, source);
			const TCHAR *ext = _tcsrchr (tmp, '.');
			if (!ext || _tcsicmp (ext, _T(".lnk")) != 0)
				_tcscat (tmp, _T(".lnk"));
            hres = ppf->Save(tmp, TRUE); 
            ppf->Release(); 
        } 
        psl->Release(); 
    }
	return SUCCEEDED(hres);
}
开发者ID:engur,项目名称:WinUAE,代码行数:36,代码来源:fsdb_mywin32.cpp

示例7: CreateLink

HRESULT CSysDialog::CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc)
{
    HRESULT hres;
    IShellLink* psl;

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

        psl->SetPath(lpszPathObj);
        psl->SetDescription(lpszDesc);
        hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
        if (SUCCEEDED(hres)) {
            WCHAR wsz[MAX_PATH];
            
            MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
            hres = ppf->Save(wsz, TRUE);
            ppf->Release();
        }
        psl->Release();
    }
    return hres;
}
开发者ID:2Dou,项目名称:PlayBox,代码行数:25,代码来源:DlgSys.cpp

示例8: CreateLink

long CreateLink(LPCSTR lpszPathObj,LPSTR lpszPathLink,LPSTR lpszDesc)
{
	HRESULT hres;
	IShellLink* psl;
    
	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);
		if (SUCCEEDED(hres)) 
		{ 
            WCHAR wsz[MAX_PATH];
			ZeroMemory(wsz,sizeof(WORD)*MAX_PATH);
			hres = psl->SetPath(lpszPathObj); 
			hres = psl->SetDescription(lpszDesc);  
       		hres = psl->SetIconLocation(lpszPathObj,0);
			MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
			hres = ppf->Save(wsz, TRUE); 
            ppf->Release();
			if(!SUCCEEDED(hres))
				return false;
		} 
		else
			return false;
        psl->Release();
	}
	else
		return false;
	CoUninitialize();
	return true;
}
开发者ID:rauls,项目名称:iReporter,代码行数:34,代码来源:createshortcuts.cpp

示例9: 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

示例10: SymLink

/*
	リンク
	あらかじめ、CoInitialize(NULL); を実行しておくこと
*/
BOOL SymLink(LPCSTR src, LPSTR dest, LPCSTR arg)
{
	IShellLink		*shellLink;
	IPersistFile	*persistFile;
	Wstr			wsrc(src), wdest(dest), warg(arg);
	BOOL			ret = FALSE;
	char			buf[MAX_PATH_U8];

	if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (void **)&shellLink))) {
		shellLink->SetPath((char *)wsrc.Buf());
		shellLink->SetArguments((char *)warg.Buf());
		GetParentDirU8(src, buf);
		shellLink->SetWorkingDirectory((char *)U8toWs(buf));

		if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) {
			if (SUCCEEDED(persistFile->Save(wdest.s(), TRUE))) {
				ret = TRUE;
				GetParentDirU8(WtoU8(wdest.s()), buf);
				::SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH|SHCNF_FLUSH, U8toAs(buf), NULL);
			}
			persistFile->Release();
		}
		shellLink->Release();
	}
	return	ret;
}
开发者ID:glukki,项目名称:ipmsg,代码行数:30,代码来源:install.cpp

示例11: 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

示例12: int

void	Shortcut_Run(const char* szLink, const char* szWorkdir) {
    wchar_t	wszLink[MAX_PATH]	= {};
    ::MultiByteToWideChar(CP_ACP, NULL, szLink, int(strlen(szLink)), wszLink, 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)) {
                int		show	= SW_SHOW;
                char	path[MAX_PATH]	= {};
                char	workdir[MAX_PATH]	= {};
                pShellLink->GetShowCmd(&show);
                pShellLink->GetPath(path, MAX_PATH, NULL, 0);
                pShellLink->GetWorkingDirectory(workdir, MAX_PATH);
                if(path[0] != 0) {
                    ShellExecute(NULL, "open", path, NULL, workdir, show);
                }
            }
            ppf->Release();
        }
        pShellLink->Release();
    }
    ::CoUninitialize();
}
开发者ID:ximenpo,项目名称:simple-cpp-win32,代码行数:31,代码来源:shortcut.cpp

示例13: 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;
}
开发者ID:Runcy,项目名称:FastCopy-M,代码行数:33,代码来源:tapi32u8.cpp

示例14: 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;
}
开发者ID:nianhuaxpj,项目名称:ipmsg,代码行数:28,代码来源:tmisc.cpp

示例15: SymLinkV

/*
	リンク
	あらかじめ、CoInitialize(NULL); を実行しておくこと
	src  ... old_path
	dest ... new_path
*/
BOOL SymLinkV(void *src, void *dest, void *arg)
{
	IShellLink		*shellLink;
	IPersistFile	*persistFile;
	WCHAR			wbuf[MAX_PATH], *ps_dest = (WCHAR *)dest;
	BOOL			ret = FALSE;
	WCHAR			buf[MAX_PATH];

	if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkV,
			(void **)&shellLink))) {
		shellLink->SetPath((char *)src);
		shellLink->SetArguments((char *)arg);
		GetParentDirV(src, buf);
		shellLink->SetWorkingDirectory((char *)buf);
		if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) {
			if (!IS_WINNT_V) {
				MultiByteToWideChar(CP_ACP, 0, (char *)dest, -1, wbuf, MAX_PATH);
				ps_dest = wbuf;
			}
			if (SUCCEEDED(persistFile->Save(ps_dest, TRUE))) {
				ret = TRUE;
				GetParentDirV(dest, buf);
				::SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATHV|SHCNF_FLUSH, buf, NULL);
			}
			persistFile->Release();
		}
		shellLink->Release();
	}
	return	ret;
}
开发者ID:nianhuaxpj,项目名称:ipmsg,代码行数:36,代码来源:tmisc.cpp


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