mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 16:02:56 +00:00
Link creation test by Martin Fuchs (slightly modified, so errors introduced
by me...) svn path=/trunk/; revision=7300
This commit is contained in:
parent
578b0d16ed
commit
585b1fea42
3 changed files with 128 additions and 0 deletions
6
reactos/apps/tests/create-links/.cvsignore
Normal file
6
reactos/apps/tests/create-links/.cvsignore
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
|
*.exe
|
||||||
|
*.coff
|
||||||
|
*.sym
|
||||||
|
*.map
|
25
reactos/apps/tests/create-links/Makefile
Normal file
25
reactos/apps/tests/create-links/Makefile
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# $Id: Makefile,v 1.1 2003/12/28 21:36:53 gvg Exp $
|
||||||
|
|
||||||
|
PATH_TO_TOP = ../../..
|
||||||
|
|
||||||
|
TARGET_NORC = yes
|
||||||
|
|
||||||
|
TARGET_TYPE = program
|
||||||
|
|
||||||
|
TARGET_APPTYPE = console
|
||||||
|
|
||||||
|
TARGET_NAME = create-links
|
||||||
|
|
||||||
|
TARGET_SDKLIBS = kernel32.a gdi32.a
|
||||||
|
|
||||||
|
TARGET_GCCLIBS = ole32 uuid shell32 shlwapi
|
||||||
|
|
||||||
|
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||||
|
|
||||||
|
TARGET_CFLAGS = -Wall -Werror -D__USE_W32API -D_WIN32_IE=0x0400
|
||||||
|
|
||||||
|
include $(PATH_TO_TOP)/rules.mak
|
||||||
|
|
||||||
|
include $(TOOLS_PATH)/helper.mk
|
||||||
|
|
||||||
|
# EOF
|
97
reactos/apps/tests/create-links/create-links.c
Normal file
97
reactos/apps/tests/create-links/create-links.c
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
compile via:
|
||||||
|
gcc -o create-links -D_WIN32_IE=0x400 create-links.c -lole32 -luuid -lshell32 -lshlwapi
|
||||||
|
|
||||||
|
Martin Fuchs, 27.12.2003
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <shlobj.h>
|
||||||
|
#include <objidl.h>
|
||||||
|
#include <shlwapi.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
HRESULT CreateShellLink(LPCSTR linkPath, LPCSTR cmd, LPCSTR arg, LPCSTR dir, LPCSTR iconPath, int icon_nr, LPCSTR comment)
|
||||||
|
{
|
||||||
|
IShellLinkA* psl;
|
||||||
|
IPersistFile* ppf;
|
||||||
|
WCHAR buffer[MAX_PATH];
|
||||||
|
|
||||||
|
HRESULT hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&psl);
|
||||||
|
|
||||||
|
printf("creating shortcut file '%s' to %s...\n", linkPath, cmd);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
hr = psl->lpVtbl->SetPath(psl, cmd);
|
||||||
|
|
||||||
|
if (arg)
|
||||||
|
hr = psl->lpVtbl->SetArguments(psl, arg);
|
||||||
|
|
||||||
|
if (dir)
|
||||||
|
hr = psl->lpVtbl->SetWorkingDirectory(psl, dir);
|
||||||
|
|
||||||
|
if (iconPath)
|
||||||
|
hr = psl->lpVtbl->SetIconLocation(psl, iconPath, icon_nr);
|
||||||
|
|
||||||
|
if (comment)
|
||||||
|
hr = psl->lpVtbl->SetDescription(psl, comment);
|
||||||
|
|
||||||
|
hr = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, linkPath, -1, buffer, MAX_PATH);
|
||||||
|
|
||||||
|
hr = ppf->lpVtbl->Save(ppf, buffer, TRUE);
|
||||||
|
|
||||||
|
ppf->lpVtbl->Release(ppf);
|
||||||
|
}
|
||||||
|
|
||||||
|
psl->lpVtbl->Release(psl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
printf("OK\n\n");
|
||||||
|
else
|
||||||
|
printf("error %08x\n\n", (int) hr);
|
||||||
|
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char path[MAX_PATH];
|
||||||
|
LPSTR p;
|
||||||
|
|
||||||
|
CoInitialize(NULL);
|
||||||
|
|
||||||
|
/* create some shortcuts in the start menu "programs" folder */
|
||||||
|
SHGetSpecialFolderPathA(0, path, CSIDL_PROGRAMS, TRUE);
|
||||||
|
p = PathAddBackslash(path);
|
||||||
|
|
||||||
|
strcpy(p, "start-cmd.lnk");
|
||||||
|
CreateShellLink(path, "cmd.exe", "", NULL, NULL, 0, "open console window");
|
||||||
|
|
||||||
|
strcpy(p, "start-winhello.lnk");
|
||||||
|
CreateShellLink(path, "winhello.exe", "", NULL, NULL, 0, "launch winhello");
|
||||||
|
|
||||||
|
|
||||||
|
/* create some shortcuts on the desktop */
|
||||||
|
SHGetSpecialFolderPathA(0, path, CSIDL_DESKTOP, TRUE);
|
||||||
|
p = PathAddBackslash(path);
|
||||||
|
|
||||||
|
strcpy(p, "start-wcmd.lnk");
|
||||||
|
CreateShellLink(path, "cmd.exe", "", NULL, NULL, 0, "open console window");
|
||||||
|
|
||||||
|
strcpy(p, "start-winemine.lnk");
|
||||||
|
CreateShellLink(path, "winemine.exe", "", NULL, NULL, 0, "launch winemine");
|
||||||
|
|
||||||
|
CoUninitialize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue