File: createLink.ec

package info (click to toggle)
ecere-sdk 0.44.15-1
  • links: PTS
  • area: main
  • in suites: sid, stretch
  • size: 97,712 kB
  • ctags: 54,695
  • sloc: ansic: 593,042; makefile: 12,250; yacc: 4,955; lex: 707; objc: 259; python: 252; xml: 102
file content (51 lines) | stat: -rw-r--r-- 1,398 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#define UNICODE
#define Method _Method
#define Array _Array
#define byte _byte
#define int64 _int64
#include <shlobj.h>
#undef Method
#undef Array
#undef byte
#undef int64

#ifdef ECERE_STATIC
import static "ecere"
#else
import "ecere"
#endif

bool CreateLink(char * lpszPathObj, char * lpszPathLink, char * lpszDesc)
{
    HRESULT hres;
    IShellLink* psl;

    CoInitialize(NULL);
    hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void *)&psl);
    if (SUCCEEDED(hres))
    {
        IPersistFile * ppf;
        uint16 pathObj[2048] = { 0 };
        uint16 desc[2048] = { 0 };

        UTF8toUTF16Buffer(lpszPathObj, pathObj, sizeof(pathObj) / sizeof(uint16));
        UTF8toUTF16Buffer(lpszDesc, desc, sizeof(desc) / sizeof(uint16));
        IShellLinkW_SetPath(psl, pathObj);
        IShellLinkW_SetDescription(psl, desc);

        //hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile, (void *)&ppf);
        hres = IShellLinkW_QueryInterface(psl, &IID_IPersistFile, (void *)&ppf);

        if(SUCCEEDED(hres))
        {
            WCHAR wsz[MAX_PATH];
            MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
            hres = IPersistFile_Save(ppf, wsz, TRUE);
            IPersistFile_Release(ppf);
        }
        IShellLinkW_Release(psl);
    }
    return hres == 0;
}