diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/external_dependencies/openmpt-trunk/mptrack/MPTrackUtil.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/mptrack/MPTrackUtil.cpp')
-rw-r--r-- | Src/external_dependencies/openmpt-trunk/mptrack/MPTrackUtil.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Src/external_dependencies/openmpt-trunk/mptrack/MPTrackUtil.cpp b/Src/external_dependencies/openmpt-trunk/mptrack/MPTrackUtil.cpp new file mode 100644 index 00000000..dbc00d9d --- /dev/null +++ b/Src/external_dependencies/openmpt-trunk/mptrack/MPTrackUtil.cpp @@ -0,0 +1,85 @@ +/* + * MPTrackUtil.cpp + * --------------- + * Purpose: Various useful utility functions. + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#include "stdafx.h" +#include "MPTrackUtil.h" + + +OPENMPT_NAMESPACE_BEGIN + + +static bool CreateShellLink(const IID &type, const mpt::PathString &path, const mpt::PathString &target, const mpt::ustring &description) +{ + HRESULT hres = 0; + IShellLink *psl = nullptr; + hres = CoCreateInstance(type, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); + if(SUCCEEDED(hres)) + { + IPersistFile *ppf = nullptr; + psl->SetPath(target.AsNative().c_str()); + psl->SetDescription(mpt::ToWin(description).c_str()); + hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf); + if(SUCCEEDED(hres)) + { + hres = ppf->Save(path.ToWide().c_str(), TRUE); + ppf->Release(); + ppf = nullptr; + } + psl->Release(); + psl = nullptr; + } + return SUCCEEDED(hres); +} + + +bool CreateShellFolderLink(const mpt::PathString &path, const mpt::PathString &target, const mpt::ustring &description) +{ + return CreateShellLink(CLSID_FolderShortcut, path, target, description); +} + + +bool CreateShellFileLink(const mpt::PathString &path, const mpt::PathString &target, const mpt::ustring &description) +{ + return CreateShellLink(CLSID_ShellLink, path, target, description); +} + + +mpt::const_byte_span GetResource(LPCTSTR lpName, LPCTSTR lpType) +{ + HINSTANCE hInstance = AfxGetInstanceHandle(); + HRSRC hRsrc = FindResource(hInstance, lpName, lpType); + if(hRsrc == NULL) + { + return mpt::const_byte_span(); + } + HGLOBAL hGlob = LoadResource(hInstance, hRsrc); + if(hGlob == NULL) + { + return mpt::const_byte_span(); + } + return mpt::const_byte_span(mpt::void_cast<const std::byte *>(LockResource(hGlob)), SizeofResource(hInstance, hRsrc)); + // no need to call FreeResource(hGlob) or free hRsrc, according to MSDN +} + + +CString LoadResourceString(UINT nID) +{ + CString str; + BOOL resourceLoaded = str.LoadString(nID); + MPT_ASSERT(resourceLoaded); + if(!resourceLoaded) + { + return _T(""); + } + return str; +} + + +OPENMPT_NAMESPACE_END |