本文整理汇总了C++中IPersistFile::Save方法的典型用法代码示例。如果您正苦于以下问题:C++ IPersistFile::Save方法的具体用法?C++ IPersistFile::Save怎么用?C++ IPersistFile::Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPersistFile
的用法示例。
在下文中一共展示了IPersistFile::Save方法的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: CreateLnkOnDesktop
void CreateLnkOnDesktop(const LPWSTR connTitle)
{
IShellLink *SLink;
IPersistFile *PF;
HRESULT HRes;
TCHAR desktop_path[MAX_PATH] = TEXT("");
TCHAR pszFullLnkPath[MAX_PATH];
CoInitialize(NULL);
ITEMIDLIST* pidl1 = NULL;
SHGetFolderLocation(NULL, CSIDL_CONNECTIONS, NULL, 0, &pidl1);
IShellFolder *desktop, *ncfolder;
SHGetDesktopFolder(&desktop);
desktop->BindToObject(pidl1, NULL, IID_IShellFolder, (void**)&ncfolder);
IEnumIDList *items;
ncfolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &items);
ITEMIDLIST* pidl2 = NULL;
while (S_OK == items->Next(1, &pidl2, NULL))
{
STRRET sr = {STRRET_WSTR};
ncfolder->GetDisplayNameOf(pidl2, SHGDN_NORMAL, &sr);
TCHAR buf[MAX_PATH] = TEXT("");
StrRetToBuf(&sr, pidl2, buf, MAX_PATH);
if (0 == StrCmpI(buf, connTitle))
{
ITEMIDLIST* pidl3 = ILCombine(pidl1, pidl2);
HRESULT HRes = CoCreateInstance(CLSID_ShellLink, 0, CLSCTX_INPROC_SERVER, IID_IShellLink, ( LPVOID*)&SLink);
SLink->SetIDList(pidl3);
SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, desktop_path);
StringCbPrintf(pszFullLnkPath, MAX_PATH * sizeof(TCHAR), TEXT("%s\\%s.lnk"), desktop_path, connTitle);
HRes = SLink->QueryInterface(IID_IPersistFile, (LPVOID*)&PF);
HRes = PF->Save((LPCOLESTR)pszFullLnkPath, TRUE);
PF->Release();
SLink->Release();
ILFree(pidl3);
ILFree(pidl2);
break;
}
ILFree(pidl2);
pidl2 = NULL;
}
ncfolder->Release();
desktop->Release();
ILFree(pidl1);
CoUninitialize();
}
示例3: sizeof
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();
}
}
示例4: 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);
}
示例5: 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
}
示例6: 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;
}
示例7: Shortcut_Create
BOOL Shortcut_Create (LPTSTR pszTarget, LPCTSTR pszSource, LPTSTR pszDesc, LPTSTR pszArgs)
{
IShellLink *psl;
HRESULT rc = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
if (SUCCEEDED (rc))
{
IPersistFile *ppf;
rc = psl->QueryInterface (IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED (rc))
{
rc = psl->SetPath (pszSource);
if (SUCCEEDED (rc))
{
rc = psl->SetDescription (pszDesc ? pszDesc : pszSource);
if (SUCCEEDED (rc))
{
if ( pszArgs )
rc = psl->SetArguments (pszArgs);
if (SUCCEEDED (rc))
{
#ifdef UNICODE
rc = ppf->Save (pszTarget, TRUE);
#else
WORD wsz[ MAX_PATH ];
MultiByteToWideChar (CP_ACP, 0, pszTarget, -1, (LPWSTR)wsz, MAX_PATH);
rc = ppf->Save ((LPCOLESTR)wsz, TRUE);
#endif
}
}
}
ppf->Release ();
}
psl->Release ();
}
return SUCCEEDED(rc) ? TRUE : FALSE;
}
示例8: CoInitialize
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;
}
示例9: 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;
}
示例10: CreateLink
/* #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 */
示例11: MarkFileUnsafe
void MarkFileUnsafe(WCHAR *wFileName)
{
HRESULT hr;
IZoneIdentifier *pizone = NULL;
IPersistFile *piper = NULL;
hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
if (FAILED(hr))
{
printf("[-] Failed CoInitializeEx - pEnroll [%x]\n", hr);
goto error;
}
hr = CoCreateInstance(CLSID_PersistentZoneIdentifier,
NULL,
CLSCTX_INPROC_SERVER,
IID_IZoneIdentifier,
(void **)&pizone);
if (FAILED(hr))
{
printf("[-] Failed CoCreateInstance - pEnroll [%x]\n", hr);
goto error;
}
if (pizone->SetId(URLZONE_INTERNET) != S_OK)
{
printf("[-] SetId failed\n");
goto error;
}
hr = pizone->QueryInterface(IID_IPersistFile, (void**)&piper);
if (FAILED(hr))
{
printf("[-] QueryInterface failed\n");
goto error;
}
hr = piper->Save(wFileName, TRUE);
if (FAILED(hr))
{
printf("[-] Failed Save\n");
goto error;
}
error:
if (pizone != NULL)
pizone->Release();
if (piper != NULL)
piper->Release();
CoUninitialize();
}
示例12: 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;
}
示例13: 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);
}
示例14: CoCreateInstance
void AGSWin32::create_shortcut(const char *pathToEXE, const char *workingFolder, const char *arguments, const char *shortcutPath)
{
IShellLink* pShellLink = NULL;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pShellLink);
if ((SUCCEEDED(hr)) && (pShellLink != NULL))
{
IPersistFile *pPersistFile = NULL;
if (FAILED(pShellLink->QueryInterface(IID_IPersistFile, (void**)&pPersistFile)))
{
this->DisplayAlert("Unable to add game tasks: QueryInterface for IPersistFile failed");
pShellLink->Release();
return;
}
// Set the path to the shortcut target and add the description
if (FAILED(pShellLink->SetPath(pathToEXE)))
{
this->DisplayAlert("Unable to add game tasks: SetPath failed");
}
else if (FAILED(pShellLink->SetWorkingDirectory(workingFolder)))
{
this->DisplayAlert("Unable to add game tasks: SetWorkingDirectory failed");
}
else if ((arguments != NULL) && (FAILED(pShellLink->SetArguments(arguments))))
{
this->DisplayAlert("Unable to add game tasks: SetArguments failed");
}
else
{
WCHAR wstrTemp[MAX_PATH] = {0};
MultiByteToWideChar(CP_ACP, 0, shortcutPath, -1, wstrTemp, MAX_PATH);
if (FAILED(pPersistFile->Save(wstrTemp, TRUE)))
{
this->DisplayAlert("Unable to add game tasks: IPersistFile::Save failed");
}
}
pPersistFile->Release();
}
if (pShellLink) pShellLink->Release();
}
示例15: 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;
}