ReactOS  0.4.14-dev-815-ge410a12
create-links.c File Reference
#include <windows.h>
#include <shlobj.h>
#include <objidl.h>
#include <shlwapi.h>
#include <stdio.h>
Include dependency graph for create-links.c:

Go to the source code of this file.

Macros

#define WIN32_LEAN_AND_MEAN
 

Functions

HRESULT CreateShellLink (LPCSTR linkPath, LPCSTR cmd, LPCSTR arg, LPCSTR dir, LPCSTR iconPath, int icon_nr, LPCSTR comment)
 
int main ()
 

Macro Definition Documentation

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 10 of file create-links.c.

Function Documentation

◆ CreateShellLink()

HRESULT CreateShellLink ( LPCSTR  linkPath,
LPCSTR  cmd,
LPCSTR  arg,
LPCSTR  dir,
LPCSTR  iconPath,
int  icon_nr,
LPCSTR  comment 
)

Definition at line 19 of file create-links.c.

20 {
21  IShellLinkA* psl;
22  IPersistFile* ppf;
24 
25  HRESULT hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&psl);
26 
27  printf("creating shortcut file '%s' to %s...\n", linkPath, cmd);
28 
29  if (SUCCEEDED(hr)) {
30  hr = psl->lpVtbl->SetPath(psl, cmd);
31 
32  if (arg)
33  hr = psl->lpVtbl->SetArguments(psl, arg);
34 
35  if (dir)
36  hr = psl->lpVtbl->SetWorkingDirectory(psl, dir);
37 
38  if (iconPath)
39  hr = psl->lpVtbl->SetIconLocation(psl, iconPath, icon_nr);
40 
41  if (comment)
42  hr = psl->lpVtbl->SetDescription(psl, comment);
43 
44  hr = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf);
45 
46  if (SUCCEEDED(hr)) {
47  MultiByteToWideChar(CP_ACP, 0, linkPath, -1, buffer, MAX_PATH);
48 
49  hr = ppf->lpVtbl->Save(ppf, buffer, TRUE);
50 
51  ppf->lpVtbl->Release(ppf);
52  }
53 
54  psl->lpVtbl->Release(psl);
55  }
56 
57  if (SUCCEEDED(hr))
58  printf("OK\n\n");
59  else
60  printf("error %08x\n\n", (int) hr);
61 
62  return hr;
63 }
#define TRUE
Definition: types.h:120
HRESULT SetPath([in] LPCSTR pszFile)
HRESULT hr
Definition: shlfolder.c:183
Definition: ftp_var.h:139
#define CP_ACP
Definition: compat.h:99
GLuint buffer
Definition: glext.h:5915
#define IID_IShellLink
Definition: shlguid.h:128
HRESULT SetIconLocation([in] LPCSTR pszIconPath, [in] int iIcon)
HRESULT SetArguments([in] LPCSTR pszArgs)
ULONG Release()
smooth NULL
Definition: ftsmooth.c:416
HRESULT SetWorkingDirectory([in] LPCSTR pszDir)
unsigned int dir
Definition: maze.c:112
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
nsrefcnt Release()
Definition: id3.c:18
HRESULT SetDescription([in] LPCSTR pszName)
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define MultiByteToWideChar
Definition: compat.h:100
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
const GUID IID_IPersistFile
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define printf
Definition: config.h:203

Referenced by main().

◆ main()

int main ( void  )

Definition at line 66 of file create-links.c.

67 {
68  char path[MAX_PATH];
69  LPSTR p;
70 
72 
73  /* create some shortcuts in the start menu "programs" folder */
76 
77  strcpy(p, "start-cmd.lnk");
78  CreateShellLink(path, "cmd.exe", "", NULL, NULL, 0, "open console window");
79 
80  strcpy(p, "start-winhello.lnk");
81  CreateShellLink(path, "winhello.exe", "", NULL, NULL, 0, "launch winhello");
82 
83 
84  /* create some shortcuts on the desktop */
87 
88  strcpy(p, "start-wcmd.lnk");
89  CreateShellLink(path, "cmd.exe", "", NULL, NULL, 0, "open console window");
90 
91  strcpy(p, "start-winemine.lnk");
92  CreateShellLink(path, "winemine.exe", "", NULL, NULL, 0, "launch winemine");
93 
95 
96  return 0;
97 }
#define TRUE
Definition: types.h:120
#define CSIDL_DESKTOP
Definition: shlobj.h:2003
char * LPSTR
Definition: xmlstorage.h:182
BOOL WINAPI SHGetSpecialFolderPathA(HWND hwndOwner, LPSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:2561
#define PathAddBackslash
Definition: shlwapi.h:783
smooth NULL
Definition: ftsmooth.c:416
#define MAX_PATH
Definition: compat.h:26
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
GLfloat GLfloat p
Definition: glext.h:8902
#define CSIDL_PROGRAMS
Definition: shlobj.h:2005