merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / test / ole / cpptest / cpptest.cxx
blobe393142fd311ab6635a3ce0f6939417a744a07eb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 // cpptest.cpp : Defines the entry point for the console application.
33 #if _MSC_VER > 1000
34 #pragma once
35 #endif // _MSC_VER > 1000
36 #pragma warning(disable: 4917)
37 #include <comdef.h>
38 #include <tchar.h>
39 #include<atlbase.h>
40 #include<atlcom.h>
42 HRESULT doTest();
44 int main(int /*argc*/, char** /*argv*/)
46 HRESULT hr;
47 if( FAILED( hr=CoInitialize(NULL)))
49 _tprintf(_T("CoInitialize failed \n"));
50 return -1;
53 if( FAILED(hr=doTest()))
55 _com_error err( hr);
56 const TCHAR * errMsg= err.ErrorMessage();
57 MessageBox( NULL, errMsg, "Test failed", MB_ICONERROR);
60 CoUninitialize();
61 return 0;
64 HRESULT doTest()
66 HRESULT hr;
67 CComPtr<IUnknown> spUnkMgr;
70 if( FAILED(hr= spUnkMgr.CoCreateInstance(L"com.sun.star.ServiceManager")))
71 return hr;
73 IDispatchPtr starManager;
74 // var starManager=new ActiveXObject("com.sun.star.ServiceManager");
75 if (FAILED(hr= starManager.CreateInstance(_T("com.sun.star.ServiceManager"))))
77 fprintf(stderr, "creating ServiceManager failed\n");
78 return hr;
80 // var starDesktop=starManager.createInstance("com.sun.star.frame.Desktop");
81 _variant_t varP1(L"com.sun.star.frame.Desktop");
82 _variant_t varRet;
83 CComDispatchDriver dispMgr(starManager);
84 if (FAILED(hr= dispMgr.Invoke1(L"createInstance", &varP1, &varRet)))
86 fprintf(stderr,"createInstance of Desktop failed\n");
87 return hr;
89 CComDispatchDriver dispDesk(varRet.pdispVal);
90 varP1.Clear();
91 varRet.Clear();
92 // var bOK=new Boolean(true);
94 // var noArgs=new Array();
95 // var oDoc=starDesktop.loadComponentFromURL("private:factory/swriter", "Test", 40, noArgs);
96 IDispatchPtr oDoc;
97 SAFEARRAY* ar= SafeArrayCreateVector(VT_DISPATCH, 0, 0);
98 _variant_t args[4];
99 args[3]= _variant_t(L"private:factory/swriter");
100 args[2]= _variant_t(L"Test");
101 args[1]= _variant_t((long) 40);
102 args[0].vt= VT_ARRAY | VT_DISPATCH;;
103 args[0].parray= ar;
104 if (FAILED(hr= dispDesk.InvokeN(L"loadComponentFromURL", args, 4, &varRet)))
106 fprintf(stderr,"loadComponentFromURL failed\n");
107 return hr;
109 CComDispatchDriver dispDoc(varRet.pdispVal);
110 varRet.Clear();
111 return S_OK;