(API) Create ShortCut Function [Danilo Code]

Blitz3D Forums/Blitz3D Programming/(API) Create ShortCut Function [Danilo Code]

virtlands(Posted 2013) [#1]
I encountered some excellent "create shortcut" code by some
PureBasic coder named Danilo. The function uses API methods.

...So I transferred his code into a DLL procedure for easy use with Blitz3D.

Click here to download my "ShellLink.DLL" code, +etc.,
http://uploadingit.com/file/clale9n6z7iwu7ry/%5BAPI%5D%20Create%20Shortcut%20Function%20_%5BDanilo%20code%5D.zip

Here's the B3D demonstration: (already included in link)


; Be sure to create some file named "ShellLink.DECLS" inside
; your B3D userlibs folder. Copy these 3 details into it:

.lib "ShellLink.dll"
createShellLink%(obj$, lnk$, arg$, desc$, dir$, icon$, index%)
getSpecialFolder$(id%)

;------------------------
The above demo code demonstrates creating a shortcut for
something like " NotePad.exe "

I'll try to explain in detail some of the variables:


obj$ = path to the object to make a link for
link$ = location and name of the actual shortcut *.LNK file
....
You may snatch away icons from other DLL files (that are already on your PC) and use them as you wish to become the icon for the LINK.
DLLs (and EXEs) typically have many icons within them.
These icons can be accessed using 'icon indexes' (=offsets)

index% = (choose the offset that you want)

To see what the real icon offsets are, use this free program
called IconsExtract
http://www.nirsoft.net/utils/iconsext.html

It was the only program that I could find that shows the true offsets.
This screenshot shows a sample of the icons found in shell32.dll


My shellLink.DLL program expects an offset starting at zero,
but the offsets shown in IconsExtract start at "1".

Therefore, you'll just have to subtract 1 to get the real thing.
Notice, for example that the green tree icon has an index of 42.
To use that icon, you must enter "41" as in "index=41"

When you then run the example code, you may end up with
an icon on your desktop that looks like this:


Of course you can place the LNK file anywhere you wish, but most
of the time they are placed on the desktop.

The getSpecialFolder(CSIDL_WINDOWS) routine will return the
path to your WINDOWS directory, { In Win7 it is "C:\WINDOWS }

The getSpecialFolder(CSIDL_DESKTOPDIRECTORY)routine will return the
path to your DESKTOP directory

The create shortcut function is:
createShellLink(obj, lnk, arg, desc, dir, icon, index)

If you want to learn about the LNK format as much as possible,
then you can download the [MS-SHLLINK] PDF,
http://msdn.microsoft.com/en-us/library/dd871305

THat PDF is about as detailed as you can possibly get.

There is also this nice program called Windows LNK Parsing utility
that will dissect LNK files, and tell you everything it finds.
http://tzworks.net/prototype_page.php?proto_id=11

The purebasic code used to create the DLL is already
included in the download link.

The original website with all the Danilo code is this one:
http://www.purebasic.fr/english/viewtopic.php?f=12&t=44477&p=340289#p340289


Hope you enjoy the program. I already tested it, and it works.