First time working with COM from C++, been using C# and Delphi before.
So here's the code
HRESULT Result;
Result = CoInitialize(nullptr);
if (!SUCCEEDED(Result))
return Result;
IShellDispatch* API;
Result = CoCreateInstance(CLSID_Shell, nullptr, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&API);
if ((!SUCCEEDED(Result)) || (nullptr == API))
goto Cleanup;
VARIANT Source1, Source2, Destination, Options;
VariantInit(&Destination);
Destination.vt = VT_BSTR;
Destination.bstrVal = SysAllocString(OutFile.c_str());
Folder* PDestination;
Result = API->NameSpace(Destination, &PDestination);
if (!SUCCEEDED(Result))
goto Cleanup;
VariantInit(&Source1);
VariantInit(&Source2);
Source1.vt = VT_BSTR;
Source2.vt = VT_BSTR;
Source1.bstrVal = SysAllocString(InFile1.c_str());
Source2.bstrVal = SysAllocString(InFile2.c_str());
VariantInit(&Options);
Options.vt = VT_I4;
Options.lVal = FOF_NO_UI;
PDestination->CopyHere(Source1, Options);
Sleep(1000);
PDestination->CopyHere(Source2, Options);
Sleep(1000);
PDestination->Release();
API->Release();
Cleanup:
CoUninitialize();
return Result;
OutFile, InFile1 and InFile2 are of type wstring as the program is (mostly) C++. I've managed to create an empty ZIP file, that's not the issue. The issue is that I get an exception claiming that PDestination is nullptr.
If it helps, the variants themselves seems to work. Inspecting them in the debugger yields the paths I provided. I've noticed though how the NameSpace-call returns an S_FALSE. Does anyone know what I can do about that?
Using a library doesn't exactly work, it's corporate code and there's some truly draconian rules when it comes to linking external code so using the Windows API is the easiest way.