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