1 /*******************************************************************************
2 * Copyright (c) 2000, 2019 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 * Paul Pazderski - Bug 547634: PathToPIDL
14 *******************************************************************************/
17 #include "com_structs.h"
18 #include "com_stats.h"
21 #define COM_NATIVE(func) Java_org_eclipse_swt_internal_ole_win32_COM_##func
23 class CFileSysBindData : public IFileSystemBindData
26 CFileSysBindData() : refCount(1)
28 ZeroMemory(&findData, sizeof(findData));
31 IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv)
34 HRESULT hr = E_NOINTERFACE;
35 if (riid == IID_IUnknown || riid == IID_IFileSystemBindData) {
36 *ppv = static_cast<IFileSystemBindData*>(this);
43 IFACEMETHODIMP_(ULONG) AddRef()
45 return InterlockedIncrement(&refCount);
48 IFACEMETHODIMP_(ULONG) Release()
50 long rc = InterlockedDecrement(&refCount);
56 IFACEMETHODIMP SetFindData(const WIN32_FIND_DATAW *pfd)
62 IFACEMETHODIMP GetFindData(WIN32_FIND_DATAW *pfd)
70 WIN32_FIND_DATAW findData;
74 * An extended version of SHParseDisplayName which use bind context to support
75 * creation of simple PIDLs in case the normal PIDL creation failed.
76 * (most likley due to non existing file/directory)
78 extern "C" HRESULT PathToPIDL(PCWSTR pszName, PIDLIST_ABSOLUTE *ppidl)
80 if (!ppidl) return E_FAIL;
84 HRESULT hr = SHParseDisplayName(pszName, nullptr, ppidl, sfgao, &sfgao);
85 if (hr == S_OK) return hr;
87 IFileSystemBindData *pfsbd = new CFileSysBindData();
88 if (!pfsbd) return E_OUTOFMEMORY;
90 WIN32_FIND_DATAW data = {};
91 pfsbd->SetFindData(&data);
95 hr = CreateBindCtx(0, &pbc);
98 BIND_OPTS bo = { sizeof(bo), 0, STGM_CREATE, 0 };
99 hr = pbc->SetBindOptions(&bo);
102 hr = pbc->RegisterObjectParam(STR_FILE_SYS_BIND_DATA, pfsbd);
106 hr = SHParseDisplayName(pszName, pbc, ppidl, sfgao, &sfgao);