本文整理汇总了C++中IShellLink类的典型用法代码示例。如果您正苦于以下问题:C++ IShellLink类的具体用法?C++ IShellLink怎么用?C++ IShellLink使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IShellLink类的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;
}
示例2: _
void CGUISetupFrame::writeDeskTop(const wxString& name, const wxString& dir)
{
TCHAR folder[MAX_PATH];
BOOL res = ::SHGetSpecialFolderPath(NULL, folder, CSIDL_DESKTOP, FALSE);
if (!res) {
::wxMessageBox(_("Cannot get the Desktop folder from Windows"), _("GUISetup Error"), wxICON_ERROR);
return;
}
wxString linkName = name + wxT(".lnk");
wxString linkPath = wxString(folder) + wxT("\\") + linkName;
wxString exePath = dir + wxT("\\UWSDR.exe");
wxString args = name;
HRESULT hRes = ::CoInitialize(NULL);
if (!SUCCEEDED(hRes)) {
::wxMessageBox(_("Cannot initialise the COM interface"), _("GUISetup Error"), wxICON_ERROR);
return;
}
IShellLink* pShellLink;
hRes = ::CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(void**)&pShellLink);
if (!SUCCEEDED(hRes)) {
::CoUninitialize();
::wxMessageBox(_("Cannot create a COM interface"), _("GUISetup Error"), wxICON_ERROR);
return;
}
pShellLink->SetPath(exePath.c_str());
pShellLink->SetArguments(args.c_str());
pShellLink->SetWorkingDirectory(dir.c_str());
TCHAR wszLinkfile[MAX_PATH];
::MultiByteToWideChar(CP_ACP, 0, linkPath.mb_str(), -1, wszLinkfile, MAX_PATH);
IPersistFile* pPersistFile;
hRes = pShellLink->QueryInterface(IID_IPersistFile, (void**)&pPersistFile);
if (!SUCCEEDED(hRes)) {
pShellLink->Release();
::CoUninitialize();
::wxMessageBox(_("Cannot query the COM interface"), _("GUISetup Error"), wxICON_ERROR);
return;
}
hRes = pPersistFile->Save(LPCOLESTR(wszLinkfile), TRUE);
if (!SUCCEEDED(hRes))
::wxMessageBox(_("Cannot save the shortcut file"), _("GUISetup Error"), wxICON_ERROR);
pPersistFile->Release();
pShellLink->Release();
::CoUninitialize();
}
示例3: CreateShellLink
//creates a shell link...in this example a Start Group item
HRESULT CreateShellLink(LPCSTR pszShortcutFile, LPSTR pszLink, LPSTR pszDesc)
{
HRESULT hres;
IShellLink* psl;
// 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))
{
WCHAR wsz[MAX_PATH];
// Set the path to the shell link target.
hres = psl->SetPath(pszShortcutFile);
if (!SUCCEEDED(hres))
MessageBox(NULL,"SetPath failed!","ERROR",MB_OK);
// Set the description of the shell link.
hres = psl->SetDescription(pszDesc);
if (!SUCCEEDED(hres))
MessageBox(NULL,"Set Description failed!","ERROR",MB_OK);
// Ensure string is ANSI.
MultiByteToWideChar(CP_ACP, 0, pszLink, -1, wsz, MAX_PATH);
// 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();
}
return (hres==S_OK);
}
示例4: CoInitialize
//----------------------------------------------------------------------------------------
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;
}
示例5: CreateShortcut
BOOL CreateShortcut(TCHAR *file, TCHAR *shortcut)
{
IShellLink *psl = NULL;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl);
if (SUCCEEDED(hr)) {
psl->SetPath(file);
IPersistFile *ppf = NULL;
hr = psl->QueryInterface(IID_IPersistFile, (void **) &ppf);
if (SUCCEEDED(hr)) {
hr = ppf->Save(shortcut, TRUE);
ppf->Release();
}
psl->Release();
}
return SUCCEEDED(hr);
}
示例6: 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);
}
示例7: CoCreateInstance
HRESULT CTaskbar7::CreateShellLink(Destination destination, IShellLink **ppShellLink)
{
USES_CONVERSION;
IShellLink *pShellLink = NULL;
IPropertyStore *pPropertyStore = NULL;
PROPVARIANT propVariant;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pShellLink));
EXIT_ON_ERROR(hr);
// Path
hr = pShellLink->SetPath(CW2A(destination.path.c_str()));
EXIT_ON_ERROR(hr);
// Arguments
hr = pShellLink->SetArguments(CW2A(destination.arguments.c_str()));
EXIT_ON_ERROR(hr);
// Working Directory
if (!destination.workingFolder.empty())
{
hr = pShellLink->SetWorkingDirectory(CW2A(destination.workingFolder.c_str()));
EXIT_ON_ERROR(hr);
}
// Icon Location
if (!destination.icon.empty())
{
hr = pShellLink->SetIconLocation(CW2A(destination.icon.c_str()), destination.iconIndex);
EXIT_ON_ERROR(hr);
}
hr = pShellLink->QueryInterface(IID_PPV_ARGS(&pPropertyStore));
EXIT_ON_ERROR(hr);
// Name
hr = InitPropVariantFromString(destination.name.c_str(), &propVariant);
EXIT_ON_ERROR(hr);
hr = pPropertyStore->SetValue(PKEY_Title, propVariant);
EXIT_ON_ERROR(hr);
hr = pPropertyStore->Commit();
EXIT_ON_ERROR(hr);
hr = pShellLink->QueryInterface(IID_PPV_ARGS(ppShellLink));
Exit:
PropVariantClear(&propVariant);
SAFE_RELEASE(pPropertyStore);
SAFE_RELEASE(pShellLink);
return hr;
}
示例8: create_shortcut
HRESULT create_shortcut(const string& target, const string& arguments, const string& save_as)
{
IShellLink* sl = NULL;
HRESULT hres;
if (SUCCEEDED(hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<void**>(&sl))))
{
sl->SetPath(target.c_str());
sl->SetArguments(arguments.c_str());
IPersistFile* pf = NULL;
if (SUCCEEDED(hres = sl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&pf))))
{
wstring name = mbyte_to_wchar(save_as.c_str());
hres = pf->Save(name.c_str(), true);
pf->Release();
}
sl->Release();
}
return hres;
}
示例9: GetI
// @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;
}
示例10: CreateLink
HRESULT CreateLink(LPCSTR linkPath, LPCWSTR targetPath, LPCWSTR args)
{
HRESULT hres;
if (!called_coinit)
{
hres = CoInitialize(NULL);
called_coinit = true;
if (!SUCCEEDED(hres))
{
wxLogError(_("Failed to initialize COM. Error 0x%08X"), hres);
return hres;
}
}
IShellLink* link;
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&link);
if (SUCCEEDED(hres))
{
IPersistFile* persistFile;
link->SetPath(targetPath);
link->SetArguments(args);
hres = link->QueryInterface(IID_IPersistFile, (LPVOID*)&persistFile);
if (SUCCEEDED(hres))
{
WCHAR wstr[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH);
hres = persistFile->Save(wstr, TRUE);
persistFile->Release();
}
link->Release();
}
return hres;
}
示例11: SHGetTargetFolderIDList
// Get the target PIDL for a folder PIDL. This deals with cases where a folder
// is an alias to a real folder, folder shortcuts, etc.
STDAPI SHGetTargetFolderIDList(LPITEMIDLIST pidlFolder, LPITEMIDLIST *ppidl)
{
IShellLink *psl;
*ppidl = NULL;
HRESULT hr = SHGetUIObjectFromFullPIDL(pidlFolder, NULL, IID_IShellLink, (void**)(&psl));
if (SUCCEEDED(hr)) {
hr = psl->GetIDList(ppidl);
psl->Release();
}
// It's not a folder shortcut so get the PIDL normally.
if (FAILED(hr)) {
*ppidl = pidlFolder;
return S_OK;
}
return hr;
}
示例12: CreateShortcutFile
bool CreateShortcutFile(const WCHAR* filePath, const WCHAR* targetPath)
{
IShellLink* psl;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
if (SUCCEEDED(hr))
{
IPersistFile* ppf;
hr = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (SUCCEEDED(hr))
{
psl->SetPath(filePath);
hr = ppf->Save(targetPath, TRUE);
ppf->Release();
}
psl->Release();
}
return SUCCEEDED(hr);
}
示例13: VSTGUI_STRRCHR
//-----------------------------------------------------------------------------
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;
}
示例14: 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;
}
示例15: 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;
}