Re: Create Windows "shortcut" (.lnk) with D?
On Sunday, 6 March 2016 at 03:13:23 UTC, 岩倉 澪 wrote: I'm creating a small installation script in D, but I've been having trouble getting shortcut creation to work! I'm a linux guy, so I don't know much about Windows programming... [...] Any help would be highly appreciated as I'm new to Windows programming in D and have no idea what I'm doing wrong! If you don't want to mess with the Windows API then you can dynamically create a script (I do this in CE installer): void createLnk(string exeName, string displayName) { import std.process: environment, executeShell; import std.file: remove, exists; import std.random: uniform; import std.conv: to; string vbsName; do vbsName = environment.get("TEMP") ~ r"\shcsh" ~ uniform(0,int.max).to!string ~ ".vbs"; while (vbsName.exists); string vbsCode = " set WshShell = CreateObject(\"WScript.shell\") strDesktop = WshShell.SpecialFolders(\"Desktop\") set lnk = WshShell.CreateShortcut(strDesktop + \"\\%s.lnk\") lnk.TargetPath = \"%s\" lnk.Save "; File vbs = File(vbsName, "w"); vbs.writefln(vbsCode, displayName, exeName); vbs.close; executeShell(vbsName); vbsName.remove; }
Re: Create Windows "shortcut" (.lnk) with D?
On Sunday, 6 March 2016 at 05:00:55 UTC, BBasile wrote: If you don't want to mess with the Windows API then you can dynamically create a script (I do this in CE installer): This might be an option but I'd prefer to use the Windows API directly. I don't know vb script and maintaining such a script inline would just add cognitive overhead I think. If I can't get it working with the Windows API; I'll probably have to do it this way though. Thanks for the suggestion!
Re: Create Windows "shortcut" (.lnk) with D?
On Sunday, 6 March 2016 at 03:13:23 UTC, 岩倉 澪 wrote: IShellLinkA* shellLink; IPersistFile* linkFile; Any help would be highly appreciated as I'm new to Windows programming in D and have no idea what I'm doing wrong! In D, interfaces are references, so it should be: IShellLinkA shellLink; IPersistFile linkFile;
Re: Create Windows "shortcut" (.lnk) with D?
On Sunday, 6 March 2016 at 11:00:35 UTC, John wrote: On Sunday, 6 March 2016 at 03:13:23 UTC, 岩倉 澪 wrote: IShellLinkA* shellLink; IPersistFile* linkFile; Any help would be highly appreciated as I'm new to Windows programming in D and have no idea what I'm doing wrong! In D, interfaces are references, so it should be: IShellLinkA shellLink; IPersistFile linkFile; That's exactly what the problem was, thank you!!
Re: Create Windows "shortcut" (.lnk) with D?
On Sunday, 6 March 2016 at 20:13:39 UTC, 岩倉 澪 wrote: On Sunday, 6 March 2016 at 11:00:35 UTC, John wrote: On Sunday, 6 March 2016 at 03:13:23 UTC, 岩倉 澪 wrote: IShellLinkA* shellLink; IPersistFile* linkFile; Any help would be highly appreciated as I'm new to Windows programming in D and have no idea what I'm doing wrong! In D, interfaces are references, so it should be: IShellLinkA shellLink; IPersistFile linkFile; That's exactly what the problem was, thank you!! You can use official specs to recreate binary file: https://msdn.microsoft.com/en-us/library/dd871305.aspx Ok, not the fastest way. :)