From 585b1fea4249851a36dfbb5cab6c5a2c86d97a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Sun, 28 Dec 2003 21:36:53 +0000 Subject: [PATCH] Link creation test by Martin Fuchs (slightly modified, so errors introduced by me...) svn path=/trunk/; revision=7300 --- reactos/apps/tests/create-links/.cvsignore | 6 ++ reactos/apps/tests/create-links/Makefile | 25 +++++ .../apps/tests/create-links/create-links.c | 97 +++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 reactos/apps/tests/create-links/.cvsignore create mode 100644 reactos/apps/tests/create-links/Makefile create mode 100644 reactos/apps/tests/create-links/create-links.c diff --git a/reactos/apps/tests/create-links/.cvsignore b/reactos/apps/tests/create-links/.cvsignore new file mode 100644 index 00000000000..d63774a7353 --- /dev/null +++ b/reactos/apps/tests/create-links/.cvsignore @@ -0,0 +1,6 @@ +*.o +*.d +*.exe +*.coff +*.sym +*.map diff --git a/reactos/apps/tests/create-links/Makefile b/reactos/apps/tests/create-links/Makefile new file mode 100644 index 00000000000..0121d7aec8c --- /dev/null +++ b/reactos/apps/tests/create-links/Makefile @@ -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 diff --git a/reactos/apps/tests/create-links/create-links.c b/reactos/apps/tests/create-links/create-links.c new file mode 100644 index 00000000000..a2b4ce0523a --- /dev/null +++ b/reactos/apps/tests/create-links/create-links.c @@ -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 + +#include +#include +#include + +#include + +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; +}