ReactOS  0.4.14-dev-317-g96040ec
fontpidl.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Font Shell Extension
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: pidl handling
5  * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
11 {
12  // Because the FontPidlEntry contains one WCHAR, we do not need to take the null terminator into account
13  size_t cbData = sizeof(FontPidlEntry) + wcslen(lpString) * sizeof(WCHAR);
14  FontPidlEntry* pidl = (FontPidlEntry*)CoTaskMemAlloc(cbData + sizeof(WORD));
15  if (!pidl)
16  return NULL;
17 
18  ZeroMemory(pidl, cbData + sizeof(WORD));
19 
20  pidl->cb = (WORD)cbData;
21  pidl->Magic = 'fp';
22  pidl->Index = Index;
23 
24  wcscpy(pidl->Name, lpString);
25  // Should be zero already, but make sure it is
26  *(WORD*)((char*)pidl + cbData) = 0;
27 
28  return (LPITEMIDLIST)pidl;
29 }
30 
31 
33 {
34  const FontPidlEntry* zipPidl = (const FontPidlEntry*)pidl;
35  if (zipPidl->Magic == 'fp')
36  return zipPidl;
37  return NULL;
38 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
const FontPidlEntry * _FontFromIL(LPCITEMIDLIST pidl)
Definition: fontpidl.cpp:32
#define ZeroMemory
Definition: winbase.h:1642
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned short WORD
Definition: ntddk_ex.h:93
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
WCHAR Name[1]
Definition: fontpidl.hpp:17
unsigned int ULONG
Definition: retypes.h:1
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:404
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LPITEMIDLIST _ILCreate(LPCWSTR lpString, ULONG Index)
Definition: fontpidl.cpp:10