Hello!
Can you tell me the simple way to use COM in plain C (not C++). Is there some books, manuals ? Or i must to learn object-oriented programming?
I don't want to write my own COM-objects - but only use Microsoft COM (example, IFileOperation);
code https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-ifileoperation-copyitem don't compile in Pure C.
Why so, or this impossible? :'(
Articles by Jeff Glatt (https://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=88625)
COM objects in plain C... (https://forum.pellesc.de/index.php?topic=4575.msg17378#msg17378)
#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;
}