22template<
class... Args>
23HRESULT LOStart(Args... args)
25 auto quote = [](
const std::wstring& s) {
return L
"\"" + s + L
"\""; };
26 std::wstring sCmdLine((quote(
GetHelperExe()) + ... + (L
" " + quote(args))));
27 LPWSTR pCmdLine =
const_cast<LPWSTR
>(sCmdLine.c_str());
31 si.dwFlags = STARTF_USESHOWWINDOW;
32 si.wShowWindow = SW_SHOW;
33 PROCESS_INFORMATION pi = {};
34 if (!CreateProcessW(
nullptr, pCmdLine,
nullptr,
nullptr, FALSE, 0,
nullptr,
nullptr, &si, &pi))
35 return HRESULT_FROM_WIN32(GetLastError());
37 WaitForSingleObject(pi.hProcess, INFINITE);
39 const bool bGotExitCode = GetExitCodeProcess(pi.hProcess, &nExitCode);
40 const DWORD nGetExitCodeError = GetLastError();
42 CloseHandle(pi.hProcess);
43 CloseHandle(pi.hThread);
46 return HRESULT_FROM_WIN32(nGetExitCodeError);
54VARIANT_BOOL toVBool(
bool b) {
return b ? VARIANT_TRUE : VARIANT_FALSE; }
56HRESULT ImplCreateNewDocument(IDispatch* , BSTR bstrTemplateLocation,
57 BSTR bstrDefaultSaveLocation, VARIANT_BOOL* pbResult)
59 HRESULT
hr = LOStart(L
"CreateNewDocument", bstrTemplateLocation, bstrDefaultSaveLocation);
60 *pbResult = toVBool(hr == S_OK);
64HRESULT ImplEditDocument(IDispatch* , BSTR bstrDocumentLocation,
65 VARIANT_BOOL fUseLocalCopy,
const VARIANT& varProgID,
66 VARIANT_BOOL* pbResult)
68 const wchar_t* sUseLocalCopy = (fUseLocalCopy == VARIANT_FALSE) ? L
"0" : L
"1";
69 const wchar_t* sProgId = (varProgID.vt ==
VT_BSTR) ? varProgID.bstrVal : L
"";
70 HRESULT hr = LOStart(L
"EditDocument", bstrDocumentLocation, sUseLocalCopy, sProgId);
71 *pbResult = toVBool(hr == S_OK);
75HRESULT ImplViewDocument(IDispatch* , BSTR bstrDocumentLocation,
int OpenType,
76 const VARIANT& varProgID, VARIANT_BOOL* pbResult)
78 wchar_t sOpenType[16]{};
79 swprintf(sOpenType, L
"%d", OpenType);
80 const wchar_t* sProgId = (varProgID.vt ==
VT_BSTR) ? varProgID.bstrVal : L
"";
81 HRESULT hr = LOStart(L
"ViewDocument", bstrDocumentLocation, sOpenType, sProgId);
82 *pbResult = toVBool(hr == S_OK);
96 HRESULT
hr = pITypeLib->GetTypeInfoOfGuid(__uuidof(IOWSNewDocument3), &
m_pTypeInfo);
115 *ppvObject =
nullptr;
116 if (IsEqualIID(riid, __uuidof(IUnknown)) ||
117 IsEqualIID(riid, __uuidof(IDispatch)) ||
118 IsEqualIID(riid, __uuidof(IOWSNewDocument)) ||
119 IsEqualIID(riid, __uuidof(IOWSNewDocument2)) ||
120 IsEqualIID(riid, __uuidof(IOWSNewDocument3)))
122 *ppvObject =
static_cast<IOWSNewDocument3*
>(
this);
124 else if (IsEqualIID(riid, __uuidof(IObjectSafety)))
126 *ppvObject =
static_cast<IObjectSafety*
>(
this);
130 return E_NOINTERFACE;
133 static_cast<IUnknown*
>(*ppvObject)->AddRef();
141 if (pctinfo ==
nullptr)
150 if (ppTInfo ==
nullptr)
155 return DISP_E_BADINDEX;
168 return m_pTypeInfo->GetIDsOfNames(rgszNames, cNames, rgDispId);
176 DISPPARAMS *pDispParams,
178 EXCEPINFO *pExcepInfo,
181 return DispInvoke(
this,
m_pTypeInfo, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
188 BSTR bstrTemplateLocation,
189 BSTR bstrDefaultSaveLocation,
190 VARIANT_BOOL *pbResult)
192 return CreateNewDocument2(
nullptr, bstrTemplateLocation, bstrDefaultSaveLocation, pbResult);
198 BSTR bstrDocumentLocation,
200 VARIANT_BOOL *pbResult)
212 BSTR bstrDocumentLocation,
214 VARIANT_BOOL *pbResult)
216 return ViewDocument3(
nullptr, bstrDocumentLocation, 0, varProgID, pbResult);
226 BSTR bstrDocumentLocation,
228 VARIANT_BOOL *pbResult)
230 return ViewDocument3(pdisp, bstrDocumentLocation, 0, varProgID, pbResult);
237 BSTR bstrDocumentLocation,
239 VARIANT_BOOL *pbResult)
247 BSTR bstrTemplateLocation,
248 BSTR bstrDefaultSaveLocation,
249 VARIANT_BOOL* pbResult)
254 return ImplCreateNewDocument(pdisp, bstrTemplateLocation, bstrDefaultSaveLocation, pbResult);
264 VARIANT_BOOL* pbResult)
279 *pbResult = VARIANT_TRUE;
297 BSTR bstrDocumentLocation,
300 VARIANT_BOOL *pbResult)
304 return ImplViewDocument(pdisp, bstrDocumentLocation,
OpenType, varProgID, pbResult);
358 BSTR bstrDocumentLocation,
359 VARIANT_BOOL fUseLocalCopy,
361 VARIANT_BOOL *pbResult)
366 return ImplEditDocument(pdisp, bstrDocumentLocation, fUseLocalCopy, varProgID, pbResult);
382 DWORD *pdwSupportedOptions,
383 DWORD *pdwEnabledOptions)
401 DWORD dwOptionSetMask,
402 DWORD dwEnabledOptions)
HRESULT STDMETHODCALLTYPE EditDocument2(IDispatch *pdisp, BSTR bstrDocumentLocation, VARIANT varProgID, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) override
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override
HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) override
HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT *pctinfo) override
static ITypeInfo * m_pTypeInfo
HRESULT STDMETHODCALLTYPE PromptedOnLastOpen(VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE EditDocument3(IDispatch *pdisp, BSTR bstrDocumentLocation, VARIANT_BOOL fUseLocalCopy, VARIANT varProgID, VARIANT_BOOL *pbResult) override
static constexpr DWORD iSupportedOptionsMask
static LONG GetObjectCount()
virtual ~COMOpenDocuments() override
HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) override
HRESULT STDMETHODCALLTYPE DiscardLocalCheckout(BSTR bstrDocumentLocationRaw, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE EditDocument(BSTR bstrDocumentLocation, VARIANT varProgID, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE CheckinDocument(BSTR bstrDocumentLocation, int CheckinType, BSTR CheckinComment, VARIANT_BOOL bKeepCheckout, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE SetInterfaceSafetyOptions(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions) override
HRESULT STDMETHODCALLTYPE GetInterfaceSafetyOptions(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions) override
HRESULT STDMETHODCALLTYPE CreateNewDocument(BSTR bstrTemplateLocation, BSTR bstrDefaultSaveLocation, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE NewBlogPost(BSTR bstrProviderId, BSTR bstrBlogUrl, BSTR bstrBlogName) override
HRESULT STDMETHODCALLTYPE ViewDocument(BSTR bstrDocumentLocation, VARIANT varProgID, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE CheckoutDocumentPrompt(BSTR bstrDocumentLocationRaw, VARIANT_BOOL fEditAfterCheckout, VARIANT varProgID, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE CreateNewDocument2(IDispatch *pdisp, BSTR bstrTemplateLocation, BSTR bstrDefaultSaveLocation, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE ViewInExcel(BSTR SiteUrl, BSTR FileName, BSTR SessionId, BSTR Cmd, BSTR Sheet, int Row, int Column, VARIANT varProgID) override
HRESULT STDMETHODCALLTYPE ViewDocument2(IDispatch *pdisp, BSTR bstrDocumentLocation, VARIANT varProgID, VARIANT_BOOL *pbResult) override
HRESULT STDMETHODCALLTYPE ViewDocument3(IDispatch *pdisp, BSTR bstrDocumentLocation, int OpenType, VARIANT varProgID, VARIANT_BOOL *pbResult) override
ULONG STDMETHODCALLTYPE AddRef() override
const wchar_t * GetHelperExe()