i18n: Updated templates
[sdk] / extras / 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 #ifdef ECERE_STATIC
15 import static "ecere"
16 #else
17 import "ecere"
18 #endif
19
20 bool CreateLink(char * lpszPathObj, char * lpszPathLink, char * lpszDesc)
21 {
22     HRESULT hres;
23     IShellLink* psl;
24
25     CoInitialize(NULL);
26     hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void *)&psl);
27     if (SUCCEEDED(hres))
28     {
29         IPersistFile * ppf;
30         uint16 pathObj[2048] = { 0 };
31         uint16 desc[2048] = { 0 };
32
33         UTF8toUTF16Buffer(lpszPathObj, pathObj, sizeof(pathObj) / sizeof(uint16));
34         UTF8toUTF16Buffer(lpszDesc, desc, sizeof(desc) / sizeof(uint16));
35         IShellLinkW_SetPath(psl, pathObj);
36         IShellLinkW_SetDescription(psl, desc);
37
38         //hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile, (void *)&ppf);
39         hres = IShellLinkW_QueryInterface(psl, &IID_IPersistFile, (void *)&ppf);
40
41         if(SUCCEEDED(hres))
42         {
43             WCHAR wsz[MAX_PATH];
44             MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
45             hres = IPersistFile_Save(ppf, wsz, TRUE);
46             IPersistFile_Release(ppf);
47         }
48         IShellLinkW_Release(psl);
49     }
50     return hres == 0;
51 }