u_shell_link (tcshlutl.pbl)

This is a Class Builder user object that provides a very thin interface to the Windows 95 Shell COM IShellLink object. The documentation I give here mainly consists of the differences from the Win32 documentation.

This is part of my tcshlutl package.

Please note that Watcom C/C++ 11.0 is required to build the associated DLL, tcshlutl.dll

See u_shell_link_demo for a sample that demonstrates this object.

Contents

Initialisation functions

Important functions for creating shortcuts

Important functions for reading shortcuts

Less important functions for creating shortcuts

Less important functions for reading shortcuts

Tables

Examples


uf_good()

Description

Test if the underlying IShellLink object was created successfully. If the object was not created successfully call uf_error_code() to get the OLE or Win32 error code.

Returns

boolean: Non-zero if the object was created successfully.

Usage

u_shell_link uo_shell_link
if not uo_shell_link.uf_good() then
    // error
end if


uf_error_code()

Description

Get the last OLE or Win32 error or result code. This will only be an error code if the object failed to initialise correct (uf_good() returns zero) or if the last function call returned -1.

Returns

unsigned long: The last error or result code.


uf_save(string szfilename)

Description

Save the current settings of the shortcut to the named file.

Arguments

string szfilename: the name of the file to save the shortcut to. Intermediate directories are not created.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.

Implementation

Uses IShellLink::QueryInterface to get a IPersistFile interface and calls Save(szfilename, false) on it.


uf_set_path(string psz_file)

Description

Sets the path and filename for the shortcut.

Arguments

string psz_file: the path and file for the shortcut

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_set_arguments(string psz_args)

Description

Sets the command-line arguments for the shortcut.

Arguments

string psz_args: the command-line arguments string

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_set_icon_location(string psz_icon_path, long i_icon)

Description

Sets the icon for the shortcut.

Arguments

string psz_icon_location: the name of the file containing the icon long i_icon: the index of the icon in the file

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_load(string szfilename)

Description

Load the shortcuts settings from the file.

Arguments

string szfilename: the name of the file to load the shortcut from.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.

Implementation

Uses IShellLink::QueryInterface to get a IPersistFile interface and calls Load(szfilename) on it.


uf_get_path(ref string psz_file, long cch_max_path, ulong f_flags)

Description

Get the path and file for the shortcut

Arguments

ref string psz_file: where to store the path and filename. The variable passed should be initialised to space(255) or something similar before calling this function.

long cch_max_path: the amount of space available to store the path and filename in.

ulong f_flags: flags that effect the returned path. If SLGP_SHORTPATH is set then the filename will be returned in 8.3 form. If SLGP_UNCPRIORITY is set then a UNC path will be returned. These have been defined as global constants in u_shell_link.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_get_icon_location(ref string psz_icon_path, long cch_max_path, ref long pi_icon)

Description

Get the icon location for the shortcut

Arguments

ref string psz_icon_path: where to store the path to the file containing the icon. The variable passed should be initialised to space(255) or something similar before calling this function.

long cch_max_path: the amount of space available to store the icon path in.

ref long pi_icon: the index of the icon is returned here.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_set_description(string psz_name)

Description

Set the description string for the shortcut. This doesn't seem to be used for anything.

Arguments

string psz_name: the description string

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_set_hotkey(unsignedinteger w_hotkey)

Description

Set the hotkey for the shortcut.

Arguments

unsignedinteger w_hotkey: the hotkey. This has the virtual key-code in the low-order byte and a combination of modifiers in the high-order byte.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_set_show_cmd(integer i_show_cmd)

Description

Set the way that the application referred to by the shortcut will display itself (the Run item in Shortcut properties

Arguments

integer i_show_cmd: the ShowWindow() value. See the ShowCmd values table.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_set_working_directory(string psz_dir)

Description

Set the working directory for the shortcut.

Arguments

string psz_dir: the new working directory for the shortcut

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_get_hotkey(ref unsignedinteger pw_hotkey)

Description

Get the shortcuts hotkey

Arguments

unsignedinteger pw_hotkey: the hotkey is returned here. This will have the virtual key-code in the low-order byte and a combination of modifiers

in the high-order byte.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_get_show_cmd(ref integer pi_show_cmd)

Description

Get the window show command for the shortcut

Arguments

ref integer pi_show_cmd: the ShowWindow value is returned in this variable. See the ShowCmds table for a list of commands.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_get_arguments(ref string psz_args, long cch_max_path)

Description

Get the command-line arguments for the shortcut

Arguments

ref string psz_args: where to store the arguments. The variable passed should be initialised to space(255) or something similar before calling this function.

long cch_max_path: the amount of space available to store the arguments in.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.

Usage

// assuming "u_shell_link uo_shell_link" somewhere
string s_args
s_args = space(255)
if uo_shell_link.uf_get_arguments(s_args, len(s_args)) = 1 then
    // success
else
    // error
end if


uf_get_description(ref string psz_name, long cch_max_path)

Description

Get the description field from the shortcut. Windows doesn't seem to use this for anything.

Parameters

ref string psz_name: where to store the description. The variable passed should be initialised to space(255) or something similar before calling this function.

long cch_max_path: the amount of space available to store the description in.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.

Usage

// assuming "u_shell_link uo_shell_link" somewhere
string s_desc
s_desc = space(255)
if uo_shell_link.uf_get_description(s_desc, len(s_desc)) = 1 then
    // success
else
    // error
end if


uf_get_working_directory(ref string psz_dir, long cch_max_path)

Description

Get the working directory from the shortcut.

Parameters

ref string psz_dir where to store the working directory. The variable passed should be initialised to space(255) or something similar before calling this function.

long cch_max_path: the amount of space available to store the working directory in.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


uf_resolve(ulong hwnd, ulong f_flags)

Description

Attempts to resolve the shortcut to it's destination. See the Win32 SDK help documentation for details.

Arguments

ulong hwnd: handle of a window used as an owner window for a dialog box

ulong f_flags: action flags.

Returns

integer: 1 on success, -1 on failure, check uf_error_code() for an OLE error code.


Hotkey modifiers

These are used in the high-order byte of the hotkey values supplied to uf_set_hotkey() and received from uf_get_hotkey()

These have been defined as global constants in the u_shell_link user object.

ValueModifier key
HOTKEYF_ALTALT key
HOTKEYF_CONTROLControl key
HOTKEYF_EXTExtended key (eg. keypad)
HOTKEYF_SHIFTShift key


ShowCmd values

These are values supplied to the uf_set_show_cmd() and the result from the uf_get_show_cmd() functions.

These have been defined as global constants in the u_shell_link user object.

ValueWindow disposition
SW_SHOWNORMALNormal
SW_SHOWMAXIMIZEDMaximized
SW_SHOWMINNOACTIVEMinimized


Example: Creating a shortcut

As simple example that creates a shortcut

// This is a bit light on error checking
u_shell_link uo_shell_link
uo_shell_link = CREATE u_shell_link
if uo_shell_link.uf_good() then
  uo_shell_link.uf_set_path("notepad.exe")
  uo_shell_link.uf_save("h:\nt40\Profiles\All Users\Desktop\Notepad.lnk")
else
  MessageBox("Error", "Could not create link object", StopSign!)
end if


Example: Reading a shortcut

A simple example that reads in a shortcut

// This is a bit light on error checking
u_shell_link uo_shell_link
uo_shell_link = CREATE u_shell_link
if uo_shell_link.uf_good() then
  if uo_shell_link.uf_load("h:\nt40\Profiles\All Users\Desktop\Notepad.lnk") = 1 then
  uo_shell_link.uf_save("h:\nt40\Profiles\All Users\Desktop\Notepad.lnk")
    string s_path
    s_path = space(255)
    if uo_shell_link.uf_get_path(s_path, len(s_path)) = 1 then
      MessageBox("Success", "Shortcut path is :" + s_path)
    else
      MessageBox("Error", "Could not get path ", StopSign!)
    end if
  else
    MessageBox("Error", "Could not load shortcut", StopSign!)
  end if
else
  MessageBox("Error", "Could not create link object", StopSign!)
end if