1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir // cpptest.cpp : Defines the entry point for the console application.
27cdf0e10cSrcweir //
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #if _MSC_VER > 1000
30cdf0e10cSrcweir #pragma once
31cdf0e10cSrcweir #endif // _MSC_VER > 1000
32cdf0e10cSrcweir #pragma warning(disable: 4917)
33cdf0e10cSrcweir #include <comdef.h>
34cdf0e10cSrcweir #include <tchar.h>
35cdf0e10cSrcweir #include<atlbase.h>
36cdf0e10cSrcweir #include<atlcom.h>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir HRESULT doTest();
39cdf0e10cSrcweir 
main(int,char **)40cdf0e10cSrcweir int main(int /*argc*/, char** /*argv*/)
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	HRESULT hr;
43cdf0e10cSrcweir 	if( FAILED( hr=CoInitialize(NULL)))
44cdf0e10cSrcweir 	{
45cdf0e10cSrcweir 		_tprintf(_T("CoInitialize failed \n"));
46cdf0e10cSrcweir 		return -1;
47cdf0e10cSrcweir 	}
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	if( FAILED(hr=doTest()))
50cdf0e10cSrcweir 	{
51cdf0e10cSrcweir 		_com_error err( hr);
52cdf0e10cSrcweir 		const TCHAR * errMsg= err.ErrorMessage();
53cdf0e10cSrcweir 		MessageBox( NULL, errMsg, "Test failed", MB_ICONERROR);
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	CoUninitialize();
57cdf0e10cSrcweir 	return 0;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
doTest()60cdf0e10cSrcweir HRESULT doTest()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	HRESULT hr;
63cdf0e10cSrcweir 	CComPtr<IUnknown> spUnkMgr;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	if( FAILED(hr= spUnkMgr.CoCreateInstance(L"com.sun.star.ServiceManager")))
67cdf0e10cSrcweir 		return hr;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	IDispatchPtr starManager;
70cdf0e10cSrcweir     //    var starManager=new ActiveXObject("com.sun.star.ServiceManager");
71cdf0e10cSrcweir 	if (FAILED(hr= starManager.CreateInstance(_T("com.sun.star.ServiceManager"))))
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         fprintf(stderr, "creating ServiceManager failed\n");
74cdf0e10cSrcweir         return hr;
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir     //    var starDesktop=starManager.createInstance("com.sun.star.frame.Desktop");
77cdf0e10cSrcweir 	_variant_t varP1(L"com.sun.star.frame.Desktop");
78cdf0e10cSrcweir 	_variant_t varRet;
79cdf0e10cSrcweir 	CComDispatchDriver dispMgr(starManager);
80cdf0e10cSrcweir 	if (FAILED(hr=	dispMgr.Invoke1(L"createInstance", &varP1, &varRet)))
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         fprintf(stderr,"createInstance of Desktop failed\n");
83cdf0e10cSrcweir         return hr;
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 	CComDispatchDriver dispDesk(varRet.pdispVal);
86cdf0e10cSrcweir 	varP1.Clear();
87cdf0e10cSrcweir 	varRet.Clear();
88cdf0e10cSrcweir 	//    var bOK=new Boolean(true);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     //    var noArgs=new Array();
91cdf0e10cSrcweir     //    var oDoc=starDesktop.loadComponentFromURL("private:factory/swriter", "Test", 40, noArgs);
92cdf0e10cSrcweir 	IDispatchPtr oDoc;
93cdf0e10cSrcweir 	SAFEARRAY* ar= SafeArrayCreateVector(VT_DISPATCH, 0, 0);
94cdf0e10cSrcweir 	_variant_t args[4];
95cdf0e10cSrcweir 	args[3]= _variant_t(L"private:factory/swriter");
96cdf0e10cSrcweir 	args[2]= _variant_t(L"Test");
97cdf0e10cSrcweir 	args[1]= _variant_t((long) 40);
98cdf0e10cSrcweir 	args[0].vt= VT_ARRAY | VT_DISPATCH;;
99cdf0e10cSrcweir 	args[0].parray= ar;
100cdf0e10cSrcweir 	if (FAILED(hr= dispDesk.InvokeN(L"loadComponentFromURL", args, 4, &varRet)))
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         fprintf(stderr,"loadComponentFromURL failed\n");
103cdf0e10cSrcweir         return hr;
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 	CComDispatchDriver dispDoc(varRet.pdispVal);
106cdf0e10cSrcweir 	varRet.Clear();
107cdf0e10cSrcweir 	return S_OK;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir }
110