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,2020 Mark Jansen <mark.jansen@reactos.org> 6 */ 7 8 #include "precomp.h" 9 _ILCreate(LPCWSTR lpString,ULONG Index)10LPITEMIDLIST _ILCreate(LPCWSTR lpString, ULONG Index) 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 _FontFromIL(LPCITEMIDLIST pidl)32const FontPidlEntry* _FontFromIL(LPCITEMIDLIST pidl) 33 { 34 const FontPidlEntry* fontEntry = (const FontPidlEntry*)pidl; 35 if (fontEntry->Magic == 'fp') 36 return fontEntry; 37 return NULL; 38 } 39