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