« Reply #1 on: December 06, 2018, 11:26:33 AM »
Articles by Jeff GlattCOM objects in plain C...#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shellapi.h>
#include <shobjidl.h>
HRESULT CopyItem(PCWSTR pszSrcItem, PCWSTR pszDest, PCWSTR pszNewName)
{
//
// Initialize COM as STA.
//
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOperation *pfo;
//
// Create the IFileOperation interface
//
hr = CoCreateInstance(&CLSID_FileOperation,
NULL,
CLSCTX_ALL,
&IID_IFileOperation,
(void**)&pfo);
if (SUCCEEDED(hr))
{
//
// Set the operation flags. Turn off all UI from being shown to the
// user during the operation. This includes error, confirmation,
// and progress dialogs.
//
hr = pfo->lpVtbl->SetOperationFlags(pfo, FOF_NO_UI);
if (SUCCEEDED(hr))
{
//
// Create an IShellItem from the supplied source path.
//
IShellItem *psiFrom = NULL;
hr = SHCreateItemFromParsingName(pszSrcItem,
NULL,
&IID_IShellItem,
(void**)&psiFrom);
if (SUCCEEDED(hr))
{
IShellItem *psiTo = NULL;
if (NULL != pszDest)
{
//
// Create an IShellItem from the supplied
// destination path.
//
hr = SHCreateItemFromParsingName(pszDest,
NULL,
&IID_IShellItem,
(void**)&psiTo);
}
if (SUCCEEDED(hr))
{
//
// Add the operation
//
hr = pfo->lpVtbl->CopyItem(pfo, psiFrom, psiTo, pszNewName, NULL);
if (NULL != psiTo)
{
psiTo->lpVtbl->Release(psiTo);
}
}
psiFrom->lpVtbl->Release(psiFrom);
}
if (SUCCEEDED(hr))
{
//
// Perform the operation to copy the file.
//
hr = pfo->lpVtbl->PerformOperations(pfo);
}
}
//
// Release the IFileOperation interface.
//
pfo->lpVtbl->Release(pfo);
}
CoUninitialize();
}
return hr;
}
Logged
May the source be with you