diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2019-01-12 18:39:45 +0100 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2019-01-17 12:30:32 +0100 |
commit | b1247d2d0d51108c910a73891ff3116e5f032ab1 (patch) | |
tree | e9948964f0bfb1ad2df3bc7bad02aa1f41ccfbd8 /vendor/github.com/ProtonMail/go-autostart/autostart_windows.c | |
parent | efcb8312e31b5c2261b1a1e95ace55b322cfcc27 (diff) |
[pkg] all your deps are vendored to us
Diffstat (limited to 'vendor/github.com/ProtonMail/go-autostart/autostart_windows.c')
-rw-r--r-- | vendor/github.com/ProtonMail/go-autostart/autostart_windows.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/vendor/github.com/ProtonMail/go-autostart/autostart_windows.c b/vendor/github.com/ProtonMail/go-autostart/autostart_windows.c new file mode 100644 index 0000000..a61618c --- /dev/null +++ b/vendor/github.com/ProtonMail/go-autostart/autostart_windows.c @@ -0,0 +1,51 @@ +#include <windows.h> +#include <stdlib.h> +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <objbase.h> +#include <shlobj.h> + +uint64_t CreateShortcut(char *shortcutA, char *path, char *args) { + IShellLink* pISL; + IPersistFile* pIPF; + HRESULT hr; + + CoInitializeEx(NULL, COINIT_MULTITHREADED); + + // Shortcut filename: convert ANSI to unicode + WORD shortcutW[MAX_PATH]; + int nChar = MultiByteToWideChar(CP_ACP, 0, shortcutA, -1, shortcutW, MAX_PATH); + + hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&pISL); + if (!SUCCEEDED(hr)) { + return hr+0x01000000; + } + + // See https://msdn.microsoft.com/en-us/library/windows/desktop/bb774950(v=vs.85).aspx + hr = pISL->lpVtbl->SetPath(pISL, path); + if (!SUCCEEDED(hr)) { + return hr+0x02000000; + } + + hr = pISL->lpVtbl->SetArguments(pISL, args); + if (!SUCCEEDED(hr)) { + return hr+0x03000000; + } + + // Save the shortcut + hr = pISL->lpVtbl->QueryInterface(pISL, &IID_IPersistFile, (void**)&pIPF); + if (!SUCCEEDED(hr)) { + return hr+0x04000000; + } + + hr = pIPF->lpVtbl->Save(pIPF, shortcutW, FALSE); + if (!SUCCEEDED(hr)) { + return hr+0x05000000; + } + + pIPF->lpVtbl->Release(pIPF); + pISL->lpVtbl->Release(pISL); + + return 0x0; +} |