本文整理汇总了C++中IShellLink::SetPath方法的典型用法代码示例。如果您正苦于以下问题:C++ IShellLink::SetPath方法的具体用法?C++ IShellLink::SetPath怎么用?C++ IShellLink::SetPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IShellLink
的用法示例。
在下文中一共展示了IShellLink::SetPath方法的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: onFileCreateProjectShortcut
void UiPlayer::onFileCreateProjectShortcut(void)
{
WCHAR shortcutPathBuff[MAX_PATH + 1] = {0};
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = L"Shortcut (*.lnk)\0*.lnk\0";
ofn.lpstrTitle = L"Create Project Shortcut";
ofn.Flags = OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
ofn.lpstrFile = shortcutPathBuff;
ofn.nMaxFile = MAX_PATH;
if (!GetSaveFileName(&ofn)) return;
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
IShellLink* psl;
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// args
string args = m_project.makeCommandLine();
// Set the path to the shortcut target and add the description.
psl->SetPath(__wargv[0]);
wstring wargs;
wargs.assign(args.begin(), args.end());
psl->SetArguments(wargs.c_str());
psl->SetDescription(L"UiPlayer");
// 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.
size_t len = wcslen(shortcutPathBuff);
if (_wcsicmp(shortcutPathBuff + len - 4, L".lnk") != 0)
{
wcscat_s(shortcutPathBuff, L".lnk");
}
hres = ppf->Save(shortcutPathBuff, TRUE);
ppf->Release();
}
psl->Release();
}
}
示例3: CreateLnkPath
BOOL install_util::CreateLnkPath(std::wstring wsSourceFilePath, std::wstring wsDestLnkPath, std::wstring wsArgument, std::wstring wsAppId)
{
IShellLink *pisl = NULL;
HRESULT hr = CoCreateInstance(CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(void**)&pisl);
if (FAILED(hr))
{
return FALSE;
}
pisl->SetPath(wsSourceFilePath.c_str());
pisl->SetArguments(wsArgument.c_str());
int nStart = wsSourceFilePath.find_last_of(_T("/\\"));
pisl->SetWorkingDirectory(wsSourceFilePath.substr(0,nStart).c_str());
IPersistFile *plPF = NULL;
hr = pisl->QueryInterface(IID_IPersistFile, (void**)&plPF);
bool shortcut_existed = false;
if (SUCCEEDED(hr))
{
if (PathExists(wsDestLnkPath))
{
shortcut_existed = true;
install_util::DeleteFile(wsDestLnkPath.c_str());
}
if (Win7OrLater() && !wsAppId.empty() && wsAppId.length() < 64)
{
IPropertyStore *piPS = NULL;
if (SUCCEEDED(pisl->QueryInterface(IID_IPropertyStore, (void**)&piPS)))
{
PROPVARIANT property_value;
if (SUCCEEDED(InitPropVariantFromString(wsAppId.c_str(), &property_value)))
{
if (piPS->SetValue(PKEY_AppUserModel_ID, property_value) == S_OK)
piPS->Commit();
PropVariantClear(&property_value);
}
piPS->Release();
}
}
hr = plPF->Save(wsDestLnkPath.c_str(), TRUE);
plPF->Release();
}
pisl->Release();
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
return SUCCEEDED(hr);
}
示例4: CreateShortcut
//-----------------------------------------------------------------------------
// Purpose: Creates a shortcut file
//-----------------------------------------------------------------------------
bool CSystem::CreateShortcut(const char *linkFileName, const char *targetPath, const char *arguments, const char *workingDirectory, const char *iconFile)
{
#ifndef _X360
bool bSuccess = false;
char temp[MAX_PATH];
strcpy(temp, linkFileName);
// make sure it doesn't already exist
struct _stat statBuf;
if (_stat(linkFileName, &statBuf) != -1)
return false;
// Create the ShellLink object
IShellLink *psl;
HRESULT hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl);
if (SUCCEEDED(hres))
{
// Set the target information from the link object
psl->SetPath(targetPath);
psl->SetArguments(arguments);
if (workingDirectory && *workingDirectory)
{
psl->SetWorkingDirectory(workingDirectory);
}
if (iconFile && *iconFile)
{
psl->SetIconLocation(iconFile, 0);
}
// Bind the ShellLink object to the Persistent File
IPersistFile *ppf;
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);
hres = ppf->Save(wsz, TRUE);
if (SUCCEEDED(hres))
{
bSuccess = true;
}
ppf->Release();
}
psl->Release();
}
return bSuccess;
#else
return false;
#endif
}
示例5: 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;
}
示例6: _CreateShellLink
// Creates a CLSID_ShellLink to insert into the Tasks section of the Jump List. This type of Jump
// List item allows the specification of an explicit command line to execute the task.
HRESULT _CreateShellLink(PCWSTR pszArguments, PCWSTR pszTitle, IShellLink **ppsl)
{
IShellLink *psl;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));
if (SUCCEEDED(hr))
{
// Determine our executable's file path so the task will execute this application
WCHAR szAppPath[MAX_PATH];
if (GetModuleFileName(NULL, szAppPath, ARRAYSIZE(szAppPath)))
{
hr = psl->SetPath(szAppPath);
if (SUCCEEDED(hr))
{
hr = psl->SetArguments(pszArguments);
if (SUCCEEDED(hr))
{
// The title property is required on Jump List items provided as an IShellLink
// instance. This value is used as the display name in the Jump List.
IPropertyStore *pps;
hr = psl->QueryInterface(IID_PPV_ARGS(&pps));
if (SUCCEEDED(hr))
{
PROPVARIANT propvar;
hr = InitPropVariantFromString(pszTitle, &propvar);
if (SUCCEEDED(hr))
{
hr = pps->SetValue(PKEY_Title, propvar);
if (SUCCEEDED(hr))
{
hr = pps->Commit();
if (SUCCEEDED(hr))
{
hr = psl->QueryInterface(IID_PPV_ARGS(ppsl));
}
}
PropVariantClear(&propvar);
}
pps->Release();
}
}
}
}
else
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
psl->Release();
}
return hr;
}
示例7: CreateLink
bool ShellIO::CreateLink(CString fileName, LinkInfo *linkInfo, int flags)
{
IShellLink *psl;
IPersistFile *ppf;
HRESULT hRes;
bool ret = FALSE;
hRes = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
if(SUCCEEDED(hRes))
{
hRes = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if(SUCCEEDED(hRes))
{
if((flags & LI_DESCRIPTION) == LI_DESCRIPTION)
{
psl->SetDescription(linkInfo->description.GetBuffer());
}
if((flags & LI_PATH) == LI_PATH)
{
psl->SetPath(linkInfo->path.GetBuffer());
}
if((flags & LI_ARGUMENTS) == LI_ARGUMENTS)
{
psl->SetArguments(linkInfo->arguments.GetBuffer());
}
if((flags & LI_WORKDIRECTORY) == LI_WORKDIRECTORY)
{
psl->SetWorkingDirectory(linkInfo->workDirectory.GetBuffer());
}
if((flags & LI_ICONLOCATION) == LI_ICONLOCATION)
{
psl->SetIconLocation(linkInfo->iconLocation.GetBuffer(), linkInfo->iconIndex);
}
hRes = ppf->Save(fileName.GetBuffer(), FALSE);
ret = SUCCEEDED(hRes);
ppf->Release();
}
psl->Release();
}
return ret;
}
示例8: 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();
}
示例9: CreateIt
HRESULT CWipeFree::CreateIt(LPCTSTR pszShortcutFile, LPTSTR pszLink)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
CoInitialize(NULL);
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))
{
//WORD wsz[MAX_PATH];
// Set the path to the shell link target.
hres = psl->SetPath(pszShortcutFile);
if (!SUCCEEDED(hres))
AfxMessageBox(_T("SetPath failed!"));
// Set the description of the shell link.
hres = psl->SetWorkingDirectory(m_szCurDir);
if (!SUCCEEDED(hres))
AfxMessageBox(_T("SetDescription failed!"));
//// 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);
hres = ppf->Save(pszLink, TRUE);
// Release pointer to IPersistFile.
ppf->Release();
}
// Release pointer to IShellLink.
psl->Release();
}
CoUninitialize();
return hres;
}
示例10: newshortcut
/***
@brief [Windows限定]新しいショートカットを作成します。
@param
lnkpath: 作成するショートカットのパス
reqpath: ショートカット先のパス
@return true...成功 false...失敗
*/
bool newshortcut(const std::string & lnkpath, const std::string & reqpath)
{
bool result = false;
//COMの初期化
CoInitialize(NULL);
//IShellLink インターフェースを取得
IShellLink* psl;
HRESULT did_get_link = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<void **>(&psl));
if (SUCCEEDED(did_get_link))
{
//IPersistFile インターフェースを取得
IPersistFile* ppf;
HRESULT did_get_file = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void **>(&ppf));
if (SUCCEEDED(did_get_file))
{
//リンク元のパスを設定
HRESULT did_set_path = psl->SetPath(reqpath.c_str());
if (SUCCEEDED(did_set_path))
{
#ifdef UNICODE
HRESULT did_save = ppf->Save(lnkpath.c_str(), TRUE);
if (SUCCEEDED(did_save))
{
result = true;
}
#else
WCHAR shortcut_file_path[MAX_PATH];
if (MultiByteToWideChar(CP_ACP, 0, lnkpath.c_str(), -1, shortcut_file_path, MAX_PATH) > 0)
{
//ショートカットファイルの保存
HRESULT did_save = ppf->Save(shortcut_file_path, TRUE);
if (SUCCEEDED(did_save))
{
result = true;
}
}
#endif
}
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return result;
}
示例11: CoCreateInstance
/* #FN#
Uses the shell's IShellLink and IPersistFile interfaces
to create and store a shortcut to the specified object */
HRESULT
/* #AS#
Result of calling member functions of the interfaces */
CWizardStep1::
CreateLink(
LPCSTR lpszPathObj, /* #IN# Address of a buffer containing the path of the object */
LPCSTR lpszPathLink, /* #IN# Address of a buffer containing the path where the shell link is to be stored */
LPCSTR lpszDesc /* #IN# Address of a buffer containing the description of the shell link */
)
{
HRESULT hResult;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
hResult = CoCreateInstance( CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(LPVOID *)&psl );
if( SUCCEEDED(hResult) )
{
IPersistFile *ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath( lpszPathObj );
psl->SetDescription( lpszDesc );
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hResult = psl->QueryInterface( IID_IPersistFile, (LPVOID *)&ppf );
if( SUCCEEDED(hResult) )
{
WCHAR wsz[ MAX_PATH + 1 ];
// Ensure that the string is Unicode.
MultiByteToWideChar( CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH );
// Save the link by calling IPersistFile::Save.
hResult = ppf->Save( wsz, TRUE );
ppf->Release();
}
psl->Release();
}
return hResult;
} /* #OF# CWizardStep1::CreateLink */
示例12: CreateLink
HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
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(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
// TODO: Check return value from MultiByteWideChar to ensure
/*
* if(!IconLocation.IsEmpty())
{
hr = psl->SetIconLocation(IconLocation, IconIndex);
#ifdef _DEBUG
if(FAILED(hr))
TRACE("IconLocation not changed!\n");
#endif
}
*/
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
示例13: CreateShortcut
HRESULT CreateShortcut(LPCSTR pszPathObj,LPSTR pszParam,LPSTR pszPath,LPSTR pszPathLink,LPSTR pszDesc)
{
HRESULT hres; //调用 COM 接口方法之后的返回值
IShellLink *pShellLink;
IPersistFile *pPersistFile;
WCHAR wsz[MAX_PATH]; //UNICODE串, 用来存放快捷方式文件名
CoInitialize(NULL); //初始化 COM 库
//创建 COM 对象并获取其实现的接口
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,IID_IShellLink,(void **)&pShellLink);
if(FAILED(hres))
{
pShellLink ->Release(); //释放 IShellLink 接口
CoUninitialize(); //关闭 COM 库, 释放所有 COM 资源
return FALSE;
}
//设置快捷方式的各种属性
pShellLink->SetPath(pszPathObj); //快捷方式所指的应用程序名
pShellLink->SetArguments(pszParam); //参数
pShellLink->SetDescription(pszDesc); //描述
pShellLink->SetWorkingDirectory(pszPath); //设置工作目录
//pShellLink->SetIconLocation("C:\\Icon.ico",0); //快捷方式的图标
//pShellLink->SetHotkey(热键); //启动快捷方式的热键(只能是Ctrl+Alt+_)
//pShellLink->SetShowCmd(SW_MAXIMIZE); //运行方式(常规窗口,最大化,最小化)
//查询 IShellLink 接口从而得到 IPersistFile 接口来保存快捷方式
hres = pShellLink->QueryInterface(IID_IPersistFile,(void **)&pPersistFile);
if(FAILED(hres))
{
pPersistFile ->Release(); //释放 IPersistFile 接口
pShellLink ->Release(); //释放 IShellLink 接口
CoUninitialize(); //关闭 COM 库, 释放所有 COM 资源
return(FALSE);
}
//转换 ANSI 串为 UNICODE 串(COM 内部使用 NUICODE)
MultiByteToWideChar(CP_ACP, 0, pszPathLink, -1, wsz, MAX_PATH);
//使用 IPersistFile 接口的 Save() 方法保存快捷方式
hres = pPersistFile ->Save(wsz, TRUE);
//释放 IPersistFile 接口
pPersistFile ->Release();
//释放 IShellLink 接口
pShellLink ->Release();
//关闭 COM 库, 释放所有 COM 资源
CoUninitialize();
return(hres);
}
示例14: CreateLink
HRESULT CreateLink(LPCTSTR lpszPathObj, LPCTSTR lpszPathLink, LPCTSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
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(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
#if !( defined (_UNICODE) || defined(UNICODE) )
size_t length = wxConvFile.ToWChar(NULL, 0, lpszPathLink);
wchar_t * UnicodePath = new wchar_t [length];
size_t res = wxConvFile.ToWChar(UnicodePath, length, lpszPathLink);
(void)res; // warning fix when unicode=0 debug=0
assert(res != wxCONV_FAILED);
#else
const wchar_t *UnicodePath = lpszPathLink;
#endif
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(UnicodePath, TRUE);
ppf->Release();
#if !( defined (_UNICODE) || defined(UNICODE) )
delete [] UnicodePath;
#endif
}
psl->Release();
}
return hres;
}
示例15: 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);
}