mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Refactoring builder .com example
This commit is contained in:
224
DesktopEditor/doctrenderer/docbuilder.com/src/docbuilder_midl.h
Normal file
224
DesktopEditor/doctrenderer/docbuilder.com/src/docbuilder_midl.h
Normal file
@ -0,0 +1,224 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "C++ compiler required"
|
||||
#endif
|
||||
|
||||
#include "rpc.h"
|
||||
#include "rpcndr.h"
|
||||
|
||||
#ifndef COM_NO_WINDOWS_H
|
||||
#include "windows.h"
|
||||
#include "ole2.h"
|
||||
#endif /*COM_NO_WINDOWS_H*/
|
||||
|
||||
/* Forward Declarations */
|
||||
typedef interface IONLYOFFICEDocBuilderValue IONLYOFFICEDocBuilderValue;
|
||||
typedef interface IONLYOFFICEDocBuilderContextScope IONLYOFFICEDocBuilderContextScope;
|
||||
typedef interface IONLYOFFICEDocBuilderContext IONLYOFFICEDocBuilderContext;
|
||||
typedef interface IONLYOFFICEDocBuilder IONLYOFFICEDocBuilder;
|
||||
|
||||
typedef class CONLYOFFICEDocBuilderValue CONLYOFFICEDocBuilderValue;
|
||||
typedef class CONLYOFFICEDocBuilderContextScope CONLYOFFICEDocBuilderContextScope;
|
||||
typedef class CONLYOFFICEDocBuilderContext CONLYOFFICEDocBuilderContext;
|
||||
typedef class CONLYOFFICEDocBuilder CONLYOFFICEDocBuilder;
|
||||
|
||||
MIDL_INTERFACE("2637FDFA-8473-4CB8-B90B-C23CB949D009")
|
||||
IONLYOFFICEDocBuilderValue : public IDispatch
|
||||
{
|
||||
public:
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateInstance(
|
||||
/* [optional][in] */ VARIANT value) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsEmpty(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Clear( void) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsNull(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsUndefined(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsBool(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsInt(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsDouble(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsString(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsFunction(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsObject(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsArray(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsTypedArray(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetLength(
|
||||
/* [retval][out] */ long *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE ToBool(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE ToInt(
|
||||
/* [retval][out] */ long *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE ToDouble(
|
||||
/* [retval][out] */ double *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE ToString(
|
||||
/* [retval][out] */ BSTR *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetProperty(
|
||||
/* [in] */ BSTR name,
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Get(
|
||||
/* [in] */ long index,
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetProperty(
|
||||
/* [in] */ BSTR name,
|
||||
/* [in] */ IONLYOFFICEDocBuilderValue *value) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Set(
|
||||
/* [in] */ long index,
|
||||
/* [in] */ IONLYOFFICEDocBuilderValue *value) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Call(
|
||||
/* [in] */ BSTR name,
|
||||
/* [optional][in] */ VARIANT val1,
|
||||
/* [optional][in] */ VARIANT val2,
|
||||
/* [optional][in] */ VARIANT val3,
|
||||
/* [optional][in] */ VARIANT val4,
|
||||
/* [optional][in] */ VARIANT val5,
|
||||
/* [optional][in] */ VARIANT val6,
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
};
|
||||
|
||||
MIDL_INTERFACE("656ae95c-ae91-4dc0-88bf-0b770fc2d552")
|
||||
IONLYOFFICEDocBuilderContextScope : public IDispatch
|
||||
{
|
||||
public:
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Close( void) = 0;
|
||||
|
||||
};
|
||||
|
||||
MIDL_INTERFACE("0416975a-65c3-4015-85e4-55d9dafec5fc")
|
||||
IONLYOFFICEDocBuilderContext : public IDispatch
|
||||
{
|
||||
public:
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateUndefined(
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateNull(
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateObject(
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateArray(
|
||||
/* [in] */ long length,
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateTypedArray(
|
||||
/* [in] */ VARIANT buffer,
|
||||
/* [in] */ long length,
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetGlobal(
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateScope(
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderContextScope **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsError(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
};
|
||||
|
||||
MIDL_INTERFACE("0C07B7E7-86A4-42E1-8E42-2FA961992E0F")
|
||||
IONLYOFFICEDocBuilder : public IDispatch
|
||||
{
|
||||
public:
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateInstance( void) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE OpenFile(
|
||||
/* [in] */ BSTR path,
|
||||
/* [in] */ BSTR params,
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CreateFile(
|
||||
/* [in] */ BSTR type,
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetTmpFolder(
|
||||
/* [in] */ BSTR folder) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE SaveFile(
|
||||
/* [in] */ BSTR type,
|
||||
/* [in] */ BSTR path,
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE CloseFile( void) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE ExecuteCommand(
|
||||
/* [in] */ BSTR command,
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Run(
|
||||
/* [in] */ BSTR path,
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE RunText(
|
||||
/* [in] */ BSTR commands,
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE SetProperty(
|
||||
/* [in] */ BSTR key,
|
||||
/* [in] */ BSTR value) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Execute(
|
||||
/* [in] */ BSTR command,
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderValue **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE WriteData(
|
||||
/* [in] */ BSTR path,
|
||||
/* [in] */ BSTR value,
|
||||
/* [in] */ VARIANT_BOOL append) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE IsSaveWithDoctrendererMode(
|
||||
/* [retval][out] */ VARIANT_BOOL *result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE GetContext(
|
||||
/* [retval][out] */ IONLYOFFICEDocBuilderContext **result) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Initialize( void) = 0;
|
||||
|
||||
virtual /* [id] */ HRESULT STDMETHODCALLTYPE Dispose( void) = 0;
|
||||
|
||||
};
|
||||
|
||||
class DECLSPEC_UUID("85C41585-25D7-40F1-9CC6-FA17052650F4")
|
||||
CONLYOFFICEDocBuilderValue;
|
||||
|
||||
class DECLSPEC_UUID("c54e2b15-ff5b-45a2-aa15-89a02605c30c")
|
||||
CONLYOFFICEDocBuilderContextScope;
|
||||
|
||||
class DECLSPEC_UUID("299250bb-16c2-4ab4-8a49-a0c350d66bb5")
|
||||
CONLYOFFICEDocBuilderContext;
|
||||
|
||||
class DECLSPEC_UUID("9BF69F3C-1506-41B9-B8EE-2839948C02E9")
|
||||
CONLYOFFICEDocBuilder;
|
||||
@ -3,34 +3,23 @@
|
||||
#include <atlcomcli.h>
|
||||
#include <atlsafe.h>
|
||||
|
||||
#include "../../src/_docbuilder.h"
|
||||
#include "../../src/_docbuilder_i.c"
|
||||
#include "../../src/docbuilder_midl.h"
|
||||
|
||||
#ifdef _NATIVE_WCHAR_T_DEFINED
|
||||
# ifdef _DEBUG
|
||||
# pragma comment(lib, "comsuppwd.lib")
|
||||
# else
|
||||
#ifdef _UNICODE
|
||||
# pragma comment(lib, "comsuppw.lib")
|
||||
# endif
|
||||
#else
|
||||
# ifdef _DEBUG
|
||||
# pragma comment(lib, "comsuppd.lib")
|
||||
# else
|
||||
# pragma comment(lib, "comsupp.lib")
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#define RELEASEINTERFACE(pinterface)\
|
||||
{\
|
||||
if (pinterface!=NULL)\
|
||||
{\
|
||||
pinterface->Release();\
|
||||
pinterface=NULL;\
|
||||
}\
|
||||
#define RELEASEINTERFACE(pinterface) \
|
||||
{ \
|
||||
if (NULL != pinterface) \
|
||||
{ \
|
||||
pinterface->Release(); \
|
||||
pinterface = NULL; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
wchar_t result_path[] = L"result.docx";
|
||||
@ -46,21 +35,18 @@ int main(int argc, char *argv[])
|
||||
IONLYOFFICEDocBuilderValue* oParagraph = NULL;
|
||||
IONLYOFFICEDocBuilderValue* oContent = NULL;
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
hr = CoCreateInstance(__uuidof(CONLYOFFICEDocBuilder), NULL, CLSCTX_ALL,
|
||||
__uuidof(IONLYOFFICEDocBuilder), (void**)&oBuilder);
|
||||
HRESULT hr = CoCreateInstance(__uuidof(CONLYOFFICEDocBuilder), NULL, CLSCTX_ALL, __uuidof(IONLYOFFICEDocBuilder), (void**)&oBuilder);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
std::cout << "Failed!" << std::endl;
|
||||
exit(1);
|
||||
CoUninitialize(); \
|
||||
return 1;
|
||||
}
|
||||
|
||||
VARIANT_BOOL b;
|
||||
|
||||
oBuilder->Initialize();
|
||||
oBuilder->CreateFileW(result_path, &b);
|
||||
oBuilder->CreateFileW(_bstr_t(result_path), &b);
|
||||
oBuilder->GetContext(&oContext);
|
||||
|
||||
oContext->CreateScope(&oScope);
|
||||
@ -69,18 +55,18 @@ int main(int argc, char *argv[])
|
||||
oGlobal->GetProperty(_bstr_t("Api"), &oApi);
|
||||
oContext->CreateArray(1, &oContent);
|
||||
|
||||
oApi->Call(_bstr_t(L"GetDocument"), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), &oDocument);
|
||||
oApi->Call(_bstr_t(L"CreateParagraph"), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), &oParagraph);
|
||||
oApi->Call(_bstr_t("GetDocument"), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), &oDocument);
|
||||
oApi->Call(_bstr_t("CreateParagraph"), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), &oParagraph);
|
||||
oContext->CreateArray(1, &oContent);
|
||||
|
||||
|
||||
oParagraph->Call(_bstr_t(L"SetSpacingAfter"), ATL::CComVariant(1000), ATL::CComVariant(VARIANT_FALSE), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), NULL);
|
||||
oParagraph->Call(_bstr_t(L"AddText"), ATL::CComVariant(L"Hello from COM!"), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), NULL);
|
||||
oParagraph->Call(_bstr_t("SetSpacingAfter"), ATL::CComVariant(1000), ATL::CComVariant(VARIANT_FALSE), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), NULL);
|
||||
oParagraph->Call(_bstr_t("AddText"), ATL::CComVariant("Hello from COM!"), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), NULL);
|
||||
oContent->Set(0, oParagraph);
|
||||
|
||||
oDocument->Call(_bstr_t(L"InsertContent"), ATL::CComVariant(oContent), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), NULL);
|
||||
oDocument->Call(_bstr_t("InsertContent"), ATL::CComVariant(oContent), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), ATL::CComVariant(), NULL);
|
||||
|
||||
oBuilder->SaveFile(_bstr_t(".docx"), result_path, &b);
|
||||
oBuilder->SaveFile(_bstr_t("docx"), result_path, &b);
|
||||
|
||||
RELEASEINTERFACE(oContent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user