xref: /trunk/main/extensions/test/ole/cpptest/cpptest.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
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.
31 //
32 
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>
41 
42 HRESULT doTest();
43 
44 int main(int /*argc*/, char** /*argv*/)
45 {
46     HRESULT hr;
47     if( FAILED( hr=CoInitialize(NULL)))
48     {
49         _tprintf(_T("CoInitialize failed \n"));
50         return -1;
51     }
52 
53     if( FAILED(hr=doTest()))
54     {
55         _com_error err( hr);
56         const TCHAR * errMsg= err.ErrorMessage();
57         MessageBox( NULL, errMsg, "Test failed", MB_ICONERROR);
58     }
59 
60     CoUninitialize();
61     return 0;
62 }
63 
64 HRESULT doTest()
65 {
66     HRESULT hr;
67     CComPtr<IUnknown> spUnkMgr;
68 
69 
70     if( FAILED(hr= spUnkMgr.CoCreateInstance(L"com.sun.star.ServiceManager")))
71         return hr;
72 
73     IDispatchPtr starManager;
74     //    var starManager=new ActiveXObject("com.sun.star.ServiceManager");
75     if (FAILED(hr= starManager.CreateInstance(_T("com.sun.star.ServiceManager"))))
76     {
77         fprintf(stderr, "creating ServiceManager failed\n");
78         return hr;
79     }
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)))
85     {
86         fprintf(stderr,"createInstance of Desktop failed\n");
87         return hr;
88     }
89     CComDispatchDriver dispDesk(varRet.pdispVal);
90     varP1.Clear();
91     varRet.Clear();
92     //    var bOK=new Boolean(true);
93 
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)))
105     {
106         fprintf(stderr,"loadComponentFromURL failed\n");
107         return hr;
108     }
109     CComDispatchDriver dispDoc(varRet.pdispVal);
110     varRet.Clear();
111     return S_OK;
112 
113 }
114