4 void die(const char *message
)
7 fprintf(stderr
, "%s\n", message
);
8 fprintf(stderr
, "last error: %d\n", GetLastError());
12 int main(int argc
, char **argv
)
14 const char *progname
= argv
[0];
15 const char *work_dir
= NULL
, *arguments
= NULL
, *icon_file
= NULL
;
16 const char *description
= NULL
;
19 static WCHAR wsz
[1024];
26 if (argv
[1][0] != '-')
28 if (!strcmp(argv
[1], "--work-dir"))
30 else if (!strcmp(argv
[1], "--arguments"))
32 else if (!strcmp(argv
[1], "--show-cmd"))
33 show_cmd
= atoi(argv
[2]);
34 else if (!strcmp(argv
[1], "--icon-file"))
36 else if (!strcmp(argv
[1], "--description"))
37 description
= argv
[2];
39 fprintf(stderr
, "Unknown option: %s\n", argv
[1]);
47 if (argc
> 1 && !strcmp(argv
[1], "--")) {
53 fprintf(stderr
, "Usage: %s [options] <source> <destination>\n",
58 hres
= CoInitialize(NULL
);
60 die ("Could not initialize OLE");
62 hres
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
63 &IID_IShellLink
, (void **)&psl
);
66 die ("Could not get ShellLink interface");
68 hres
= psl
->lpVtbl
->QueryInterface(psl
, &IID_IPersistFile
,
72 die ("Could not get PersistFile interface");
74 hres
= psl
->lpVtbl
->SetPath(psl
, argv
[1]);
76 die ("Could not set path");
79 psl
->lpVtbl
->SetWorkingDirectory(psl
, work_dir
);
82 psl
->lpVtbl
->SetShowCmd(psl
, show_cmd
);
85 psl
->lpVtbl
->SetIconLocation(psl
, icon_file
, 0);
87 psl
->lpVtbl
->SetArguments(psl
, arguments
);
89 psl
->lpVtbl
->SetDescription(psl
, description
);
92 MultiByteToWideChar(CP_ACP
,
93 0, argv
[2], -1, wsz
, 1024);
94 hres
= ppf
->lpVtbl
->Save(ppf
,
95 (const WCHAR
*)wsz
, TRUE
);
97 ppf
->lpVtbl
->Release(ppf
);
98 psl
->lpVtbl
->Release(psl
);
101 die ("Could not save link");