added .gitignore for all to enjoy
[installer] / createLink.ec
1 #define COBJMACROS
2 #define WIN32_LEAN_AND_MEAN
3 #define UNICODE
4 #define Method _Method
5 #define Array _Array
6 #define byte _byte
7 #define int64 _int64
8 #include <shlobj.h>
9 #undef Method
10 #undef Array
11 #undef byte
12 #undef int64
13
14 import static "ecere"
15
16 bool CreateLink(char * lpszPathObj, char * lpszPathLink, char * lpszDesc)
17 {
18     HRESULT hres;
19     IShellLink* psl;
20
21     CoInitialize(NULL);
22     hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void *)&psl);
23     if (SUCCEEDED(hres))
24     {
25         IPersistFile * ppf;
26         uint16 pathObj[2048] = { 0 };
27         uint16 desc[2048] = { 0 };
28
29         UTF8toUTF16Buffer(lpszPathObj, pathObj, sizeof(pathObj) / sizeof(uint16));
30         UTF8toUTF16Buffer(lpszDesc, desc, sizeof(desc) / sizeof(uint16));
31         IShellLinkW_SetPath(psl, pathObj);
32         IShellLinkW_SetDescription(psl, desc);
33
34         //hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile, (void *)&ppf);
35         hres = IShellLinkW_QueryInterface(psl, &IID_IPersistFile, (void *)&ppf);
36
37         if(SUCCEEDED(hres))
38         {
39             WCHAR wsz[MAX_PATH];
40             MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
41             hres = IPersistFile_Save(ppf, wsz, TRUE);
42             IPersistFile_Release(ppf);
43         }
44         IShellLinkW_Release(psl);
45     }
46     return hres == 0;
47 }