[FONTEXT] Initial implementation
[reactos.git] / dll / shellext / fontext / fontpidl.cpp
diff --git a/dll/shellext/fontext/fontpidl.cpp b/dll/shellext/fontext/fontpidl.cpp
new file mode 100644 (file)
index 0000000..021afe1
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * PROJECT:     ReactOS Font Shell Extension
+ * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE:     pidl handling
+ * COPYRIGHT:   Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
+ */
+
+#include "precomp.h"
+
+LPITEMIDLIST _ILCreate(LPCWSTR lpString, ULONG Index)
+{
+    // Because the FontPidlEntry contains one WCHAR, we do not need to take the null terminator into account
+    size_t cbData = sizeof(FontPidlEntry) + wcslen(lpString) * sizeof(WCHAR);
+    FontPidlEntry* pidl = (FontPidlEntry*)CoTaskMemAlloc(cbData + sizeof(WORD));
+    if (!pidl)
+        return NULL;
+
+    ZeroMemory(pidl, cbData + sizeof(WORD));
+
+    pidl->cb = (WORD)cbData;
+    pidl->Magic = 'fp';
+    pidl->Index = Index;
+
+    wcscpy(pidl->Name, lpString);
+    // Should be zero already, but make sure it is
+    *(WORD*)((char*)pidl + cbData) = 0;
+
+    return (LPITEMIDLIST)pidl;
+}
+
+
+const FontPidlEntry* _FontFromIL(LPCITEMIDLIST pidl)
+{
+    const FontPidlEntry* zipPidl = (const FontPidlEntry*)pidl;
+    if (zipPidl->Magic == 'fp')
+        return zipPidl;
+    return NULL;
+}