ReactOS  0.4.13-dev-100-gc8611ae
shortcut.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "initguid.h"
#include "shlobj.h"
#include "shobjidl.h"
#include "shlguid.h"
#include "ole2.h"
#include "wine/test.h"
Include dependency graph for shortcut.c:

Go to the source code of this file.

Classes

struct  registry_value
 
struct  registry_key
 

Macros

#define COBJMACROS
 
#define REG_VALUE_ADDR(x)   ((x->dwType==REG_SZ)?(const BYTE *)x->szValue:(const BYTE *)&x->dwValue)
 
#define REG_VALUE_SIZE(x)   ((x->dwType==REG_SZ)?strlen(x->szValue)+1:sizeof(DWORD))
 

Functions

static BOOL register_keys (HKEY hRootKey, const struct registry_key *keys, unsigned int numKeys)
 
static void unregister_keys (HKEY hRootKey, const struct registry_key *keys, unsigned int numKeys)
 
static void test_ShortcutFolder (void)
 
 START_TEST (shortcut)
 

Variables

static const struct registry_value ShellFolder_values []
 
static const struct registry_value Instance_values []
 
static const struct registry_value InitPropertyBag_values []
 
static const struct registry_key Instance_keys []
 
static const struct registry_value InProcServer32_values []
 
static const struct registry_value DefaultIcon_values []
 
static const struct registry_key ShortcutCLSID_keys []
 
static const struct registry_value ShortcutCLSID_values []
 
static const struct registry_key HKEY_CLASSES_ROOT_keys []
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 37 of file shortcut.c.

◆ REG_VALUE_ADDR

#define REG_VALUE_ADDR (   x)    ((x->dwType==REG_SZ)?(const BYTE *)x->szValue:(const BYTE *)&x->dwValue)

Definition at line 61 of file shortcut.c.

◆ REG_VALUE_SIZE

#define REG_VALUE_SIZE (   x)    ((x->dwType==REG_SZ)?strlen(x->szValue)+1:sizeof(DWORD))

Definition at line 62 of file shortcut.c.

Function Documentation

◆ register_keys()

static BOOL register_keys ( HKEY  hRootKey,
const struct registry_key keys,
unsigned int  numKeys 
)
static

Definition at line 116 of file shortcut.c.

116  {
117  HKEY hKey;
118  unsigned int iKey, iValue;
119 
120  for (iKey = 0; iKey < numKeys; iKey++) {
121  if (ERROR_SUCCESS == RegCreateKeyExA(hRootKey, keys[iKey].szName, 0, NULL, 0,
122  KEY_WRITE, NULL, &hKey, NULL))
123  {
124  for (iValue = 0; iValue < keys[iKey].cValues; iValue++) {
125  const struct registry_value * value = &keys[iKey].pValues[iValue];
126  if (ERROR_SUCCESS != RegSetValueExA(hKey, value->szName, 0, value->dwType,
128  {
129  RegCloseKey(hKey);
130  return FALSE;
131  }
132  }
133 
134  if (!register_keys(hKey, keys[iKey].pSubKeys, keys[iKey].cSubKeys)) {
135  RegCloseKey(hKey);
136  return FALSE;
137  }
138 
139  RegCloseKey(hKey);
140  }
141  }
142 
143  return TRUE;
144 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
const struct registry_value * pValues
Definition: shortcut.c:66
smooth NULL
Definition: ftsmooth.c:416
#define KEY_WRITE
Definition: nt_native.h:1031
const unsigned int cValues
Definition: shortcut.c:67
#define REG_VALUE_ADDR(x)
Definition: shortcut.c:61
static BOOL register_keys(HKEY hRootKey, const struct registry_key *keys, unsigned int numKeys)
Definition: shortcut.c:116
static const WCHAR szName[]
Definition: msipriv.h:1194
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4831
LONG WINAPI RegCreateKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD Reserved, _In_ LPSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_ LPDWORD lpdwDisposition)
Definition: reg.c:1032
#define REG_VALUE_SIZE(x)
Definition: shortcut.c:62

Referenced by test_ShortcutFolder().

◆ START_TEST()

START_TEST ( shortcut  )

Definition at line 228 of file shortcut.c.

229 {
232  OleUninitialize();
233 }
static void test_ShortcutFolder(void)
Definition: shortcut.c:160
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:172
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:233

◆ test_ShortcutFolder()

static void test_ShortcutFolder ( void  )
static

Definition at line 160 of file shortcut.c.

160  {
161  LPSHELLFOLDER pDesktopFolder, pWineTestFolder;
162  IPersistFolder3 *pWineTestPersistFolder;
163  LPITEMIDLIST pidlWineTestFolder, pidlCurFolder;
164  HRESULT hr;
165  CLSID clsid;
166  const CLSID CLSID_WineTest =
167  { 0x9b352ebf, 0x2765, 0x45c1, { 0xb4, 0xc6, 0x85, 0xcc, 0x7f, 0x7a, 0xbc, 0x64 } };
168  WCHAR wszWineTestFolder[] = {
169  ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
170  'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
171 
172  /* First, we register all the necessary registry keys/values for our 'WineTest'
173  * shell object. */
175 
176  hr = SHGetDesktopFolder(&pDesktopFolder);
177  ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
178  if (FAILED(hr)) goto cleanup;
179 
180  /* Convert the wszWineTestFolder string to an ITEMIDLIST. */
181  hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
182  &pidlWineTestFolder, NULL);
183  todo_wine
184  {
186  "Expected %08x, got %08x\n", HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), hr);
187  }
188  if (FAILED(hr)) {
189  IShellFolder_Release(pDesktopFolder);
190  goto cleanup;
191  }
192 
193  /* FIXME: these tests are never run */
194 
195  /* Bind to a WineTest folder object. There has to be some support for this in shdocvw.dll.
196  * This isn't implemented in wine yet.*/
197  hr = IShellFolder_BindToObject(pDesktopFolder, pidlWineTestFolder, NULL, &IID_IShellFolder,
198  (LPVOID*)&pWineTestFolder);
199  IShellFolder_Release(pDesktopFolder);
200  ILFree(pidlWineTestFolder);
201  ok (SUCCEEDED(hr), "IShellFolder::BindToObject(WineTestFolder) failed! hr = %08x\n", hr);
202  if (FAILED(hr)) goto cleanup;
203 
204  hr = IShellFolder_QueryInterface(pWineTestFolder, &IID_IPersistFolder3, (LPVOID*)&pWineTestPersistFolder);
205  ok (SUCCEEDED(hr), "IShellFolder::QueryInterface(IPersistFolder3) failed! hr = %08x\n", hr);
206  IShellFolder_Release(pWineTestFolder);
207  if (FAILED(hr)) goto cleanup;
208 
209  /* The resulting folder object has the FolderShortcut CLSID, instead of its own. */
210  hr = IPersistFolder3_GetClassID(pWineTestPersistFolder, &clsid);
211  ok (SUCCEEDED(hr), "IPersist::GetClassID failed! hr = %08x\n", hr);
212  ok (IsEqualCLSID(&CLSID_FolderShortcut, &clsid), "GetClassId returned wrong CLSID!\n");
213 
214  pidlCurFolder = (LPITEMIDLIST)0xdeadbeef;
215  hr = IPersistFolder3_GetCurFolder(pWineTestPersistFolder, &pidlCurFolder);
216  ok (SUCCEEDED(hr), "IPersistFolder3::GetCurFolder failed! hr = %08x\n", hr);
217  ok (pidlCurFolder->mkid.cb == 20 && ((LPSHITEMID)((BYTE*)pidlCurFolder+20))->cb == 0 &&
218  IsEqualCLSID(&CLSID_WineTest, (REFCLSID)((LPBYTE)pidlCurFolder+4)),
219  "GetCurFolder returned unexpected pidl!\n");
220 
221  ILFree(pidlCurFolder);
222  IPersistFolder3_Release(pWineTestPersistFolder);
223 
224 cleanup:
226 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
HRESULT hr
Definition: shlfolder.c:183
#define REFCLSID
Definition: guiddef.h:112
#define CLSID_WineTest
Definition: marshal.c:139
unsigned char * LPBYTE
Definition: typedefs.h:52
static void unregister_keys(HKEY hRootKey, const struct registry_key *keys, unsigned int numKeys)
Definition: shortcut.c:147
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
static const struct registry_key HKEY_CLASSES_ROOT_keys[]
Definition: shortcut.c:110
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
REFCLSID clsid
Definition: msctf.c:84
#define todo_wine
Definition: test.h:154
unsigned char BYTE
Definition: mem.h:68
static BOOL register_keys(HKEY hRootKey, const struct registry_key *keys, unsigned int numKeys)
Definition: shortcut.c:116
char * cleanup(char *str)
Definition: wpickclick.c:99
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define IsEqualCLSID(rclsid1, rclsid2)
Definition: guiddef.h:91
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by START_TEST().

◆ unregister_keys()

static void unregister_keys ( HKEY  hRootKey,
const struct registry_key keys,
unsigned int  numKeys 
)
static

Definition at line 147 of file shortcut.c.

147  {
148  HKEY hKey;
149  unsigned int iKey;
150 
151  for (iKey = 0; iKey < numKeys; iKey++) {
152  if (ERROR_SUCCESS == RegOpenKeyExA(hRootKey, keys[iKey].szName, 0, DELETE, &hKey)) {
153  unregister_keys(hKey, keys[iKey].pSubKeys, keys[iKey].cSubKeys);
154  RegCloseKey(hKey);
155  }
156  RegDeleteKeyA(hRootKey, keys[iKey].szName);
157  }
158 }
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3346
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
static void unregister_keys(HKEY hRootKey, const struct registry_key *keys, unsigned int numKeys)
Definition: shortcut.c:147
LONG WINAPI RegDeleteKeyA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey)
Definition: reg.c:1225
static const WCHAR szName[]
Definition: msipriv.h:1194
#define DELETE
Definition: nt_native.h:57

Referenced by test_ShortcutFolder().

Variable Documentation

◆ DefaultIcon_values

const struct registry_value DefaultIcon_values[]
static
Initial value:
= {
{ NULL, REG_SZ,"shell32.dll,8", 0 }
}
smooth NULL
Definition: ftsmooth.c:416
#define REG_SZ
Definition: layer.c:22

Definition at line 95 of file shortcut.c.

◆ HKEY_CLASSES_ROOT_keys

const struct registry_key HKEY_CLASSES_ROOT_keys[]
static
Initial value:
= {
{ "CLSID\\{9B352EBF-2765-45C1-B4C6-85CC7F7ABC64}", ShortcutCLSID_values, 1, ShortcutCLSID_keys, 4}
}
static const struct registry_key ShortcutCLSID_keys[]
Definition: shortcut.c:99
static const struct registry_value ShortcutCLSID_values[]
Definition: shortcut.c:106

Definition at line 110 of file shortcut.c.

Referenced by test_ShortcutFolder().

◆ InitPropertyBag_values

const struct registry_value InitPropertyBag_values[]
static
Initial value:
= {
{ "Attributes", REG_DWORD, NULL, 0x00000015 },
{ "Target", REG_SZ, "C:\\", 0 }
}
smooth NULL
Definition: ftsmooth.c:416
#define REG_DWORD
Definition: sdbapi.c:596
#define REG_SZ
Definition: layer.c:22

Definition at line 81 of file shortcut.c.

◆ InProcServer32_values

const struct registry_value InProcServer32_values[]
static
Initial value:
= {
{ NULL, REG_SZ, "shdocvw.dll", 0 },
{ "ThreadingModel", REG_SZ, "Apartment", 0 }
}
smooth NULL
Definition: ftsmooth.c:416
#define REG_SZ
Definition: layer.c:22

Definition at line 90 of file shortcut.c.

◆ Instance_keys

const struct registry_key Instance_keys[]
static
Initial value:
= {
{ "InitPropertyBag", InitPropertyBag_values, 2, NULL, 0 }
}
smooth NULL
Definition: ftsmooth.c:416
static const struct registry_value InitPropertyBag_values[]
Definition: shortcut.c:81

Definition at line 86 of file shortcut.c.

◆ Instance_values

const struct registry_value Instance_values[]
static
Initial value:
= {
{ "CLSID", REG_SZ, "{0AFACED1-E828-11D1-9187-B532F1E9575D}", 0 }
}
#define REG_SZ
Definition: layer.c:22

Definition at line 77 of file shortcut.c.

◆ ShellFolder_values

const struct registry_value ShellFolder_values[]
static
Initial value:
= {
{ "WantsFORPARSING", REG_SZ, "", 0 },
{ "Attributes", REG_DWORD, NULL, 0xF8000100 }
}
smooth NULL
Definition: ftsmooth.c:416
#define REG_DWORD
Definition: sdbapi.c:596
#define REG_SZ
Definition: layer.c:22

Definition at line 72 of file shortcut.c.

◆ ShortcutCLSID_keys

const struct registry_key ShortcutCLSID_keys[]
static
Initial value:
= {
{ "DefaultIcon", DefaultIcon_values, 1, NULL, 0 },
{ "InProcServer32", InProcServer32_values, 2, NULL, 0 },
{ "Instance", Instance_values, 1, Instance_keys, 1 },
{ "ShellFolder", ShellFolder_values, 2, NULL, 0 }
}
static const struct registry_value Instance_values[]
Definition: shortcut.c:77
static const struct registry_value ShellFolder_values[]
Definition: shortcut.c:72
smooth NULL
Definition: ftsmooth.c:416
static const struct registry_value DefaultIcon_values[]
Definition: shortcut.c:95
static const struct registry_value InProcServer32_values[]
Definition: shortcut.c:90
static const struct registry_key Instance_keys[]
Definition: shortcut.c:86

Definition at line 99 of file shortcut.c.

◆ ShortcutCLSID_values

const struct registry_value ShortcutCLSID_values[]
static
Initial value:
= {
{ NULL, REG_SZ, "WineTest", 0 }
}
smooth NULL
Definition: ftsmooth.c:416
#define REG_SZ
Definition: layer.c:22

Definition at line 106 of file shortcut.c.