ショートカットファイルの作成 (Emulate_SHCreateShortcut)

WinCEにある同名のAPIと互換
(2001.05.04)
#include <comdef.h>
#include <shlobj.h>
 
#ifdef _UNICODE
    #define IShellLink    IShellLinkW
    #define IShellLinkPtr    IShellLinkWPtr
#else
    #define IShellLink    IShellLinkA
    #define IShellLinkPtr    IShellLinkAPtr
#endif
 
BOOL SHCreateShortcut(LPTSTR szShortcut, LPTSTR szTarget)
{
    if (szShortcut == NULL || szTarget == NULL)
    {
        return FALSE;
    }
   
    HRESULT hr = S_OK;
   
    try
    {
        IShellLinkPtr spShellLink;
        hr = spShellLink.CreateInstance(CLSID_ShellLink);
        if (FAILED(hr))
        {
            return FALSE;
        }
       
        hr = spShellLink->SetPath(szTarget);
        if (FAILED(hr))
        {
            return FALSE;
        }
       
        IPersistFilePtr spPersistFile = spShellLink;
        if (spPersistFile == NULL)
        {
            return FALSE;
        }
       
        hr = spPersistFile->Save(_bstr_t(szShortcut), TRUE);
        if (FAILED(hr))
        {
            return FALSE;
        }
    }
    catch (...)
    {
        return FALSE;
    }
   
    return TRUE;
}
一覧に戻る
© 2003 WAC.com All Right Reserved.