The third party app where my plugin resides supports inserting OLE objects into its documents. I'm trying to replicate/automate the feature of (for example) copying a file from Windows Explorer and pasting it in the app. If you do this with (say) a .doc file, the app will insert the file as a Word OLE object.
I have the file name and I've managed to get it inserted as an OLE "Package" - but now I'm stuck, and the documentation on the OLE functions is sparse to say the least. I guess I need to add some info to the clipbaord to identify the type of the OLE object - which I assume is derived from the file extension in some way?
From other examples online I have:
if (AfxOleInit())
{
CComPtr<IDataObject> spdto;
if (SUCCEEDED(GetUIObjectOfFile(nullptr, m_sFileName, IID_PPV_ARGS(&spdto))) &&
SUCCEEDED(OleSetClipboard(spdto)) &&
SUCCEEDED(OleFlushClipboard()))
{
// success
}
}
//------------------------------------------------------------------------------
HRESULT GetUIObjectOfFile(HWND hwnd, LPCWSTR pszPath, REFIID riid, void** ppv)
//------------------------------------------------------------------------------
{
*ppv = NULL;
HRESULT hr;
LPITEMIDLIST pidl;
SFGAOF sfgao;
//printf_s("%s", pszPath);
if (SUCCEEDED(hr = SHParseDisplayName(pszPath, NULL, &pidl, 0, &sfgao)))
{
IShellFolder* psf;
LPCITEMIDLIST pidlChild;
if (SUCCEEDED(hr = SHBindToParent(pidl, IID_IShellFolder, (void**)&psf, &pidlChild)))
{
hr = psf->GetUIObjectOf(hwnd, 1, &pidlChild, riid, NULL, ppv);
psf->Release();
}
CoTaskMemFree(pidl);
}
return hr;
}