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 // Test.cpp : Defines the entry point for the console application.
24 //
25
26 #include "stdafx.h"
27 #include "../XCallback_Impl/XCallback_Impl.h"
28 #include "../XCallback_Impl/XCallback_Impl_i.c"
29
30 CComModule _Module;
31 BEGIN_OBJECT_MAP(ObjectMap)
32 END_OBJECT_MAP()
33
34 HRESULT doTest();
35
main(int argc,char * argv[])36 int main(int argc, char* argv[])
37 {
38 HRESULT hr;
39 if( FAILED( hr=CoInitialize(NULL)))
40 {
41 _tprintf(_T("CoInitialize failed \n"));
42 return -1;
43 }
44
45
46 _Module.Init( ObjectMap, GetModuleHandle( NULL));
47
48 if( FAILED(hr=doTest()))
49 {
50 _com_error err( hr);
51 const TCHAR * errMsg= err.ErrorMessage();
52 MessageBox( NULL, errMsg, "Test failed", MB_ICONERROR);
53 }
54
55
56 _Module.Term();
57 CoUninitialize();
58
59
60 return 0;
61 }
62
63
doTest()64 HRESULT doTest()
65 {
66 HRESULT hr= S_OK;
67
68 CComPtr<IUnknown> spUnk;
69 hr= spUnk.CoCreateInstance(L"com.sun.star.ServiceManager");
70 if( FAILED( hr))
71 return hr;
72
73 CComDispatchDriver manager( spUnk);
74 CComVariant param( L"oletest.OleTest");
75 CComVariant retVal;
76 hr= manager.Invoke1((LPCOLESTR)L"createInstance", ¶m, &retVal );
77
78 CComDispatchDriver oletest( retVal.punkVal);
79
80 spUnk.Release();
81
82 hr= spUnk.CoCreateInstance(L"XCallback_Impl.Callback");
83 if( FAILED( hr))
84 return hr;
85
86 CComQIPtr<IDispatch> paramDisp(spUnk);
87
88
89 //######################################################################
90 // out parameters
91 //######################################################################
92 CComVariant param1( paramDisp);
93 CComVariant param2(1);
94
95 // oletest calls XCallback::func1
96 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
97 // XCallback::returnInterface
98 param2= 2;
99 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
100 // XCallback::outInterface
101 param2= 3;
102 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
103 // XCallback::outStruct
104 param2= 4;
105 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
106 // XCallback::outEnum
107 param2= 5;
108 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
109 // XCallback::outSeqAny
110 param2= 6;
111 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
112 // XCallback::outAny
113 param2= 7;
114 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
115 // XCallback::outBool
116 param2= 8;
117 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
118 // XCallback::outChar
119 param2= 9;
120 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
121 // XCallback::outString
122 param2= 10;
123 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
124 // XCallback::outFloat
125 param2= 11;
126 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
127 // XCallback::outDouble
128 param2= 12;
129 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
130 // XCallback::outByte
131 param2= 13;
132 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
133 // XCallback::outShort
134 param2= 14;
135 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
136 // XCallback::outLong
137 param2= 15;
138 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
139 // XCallback::outValuesMixed
140 param2= 30;
141 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
142 // XCallback::outValuesAll
143 param2= 31;
144 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
145
146 // XCallback::outSeqByte
147 // Does not work currently because Sequences are always converted to
148 // SAFEARRAY( VARIANT)
149 // param2= 32;
150 // hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
151
152 //######################################################################
153 // in / out parameters
154 //######################################################################
155 // XCallback::inoutInterface
156 param2= 100;
157 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
158 // XCallback::inoutStruct
159 param2= 101;
160 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
161 // XCallback::inoutEnum
162 param2= 102;
163 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
164 // XCallback::inoutSeqAny
165 param2= 103;
166 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
167 // XCallback::inoutAny
168 param2= 104;
169 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
170 // XCallback::inoutBool
171 param2= 105;
172 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
173 // XCallback::inoutChar
174 param2= 106;
175 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
176 // XCallback::inoutString
177 param2= 107;
178 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
179 // XCallback::inoutFloat
180 param2= 108;
181 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
182 // XCallback::inoutDouble
183 param2= 109;
184 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
185 // XCallback::inoutByte
186 param2= 110;
187 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
188 // XCallback::inoutShort
189 param2= 111;
190 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
191 // XCallback::inoutLong
192 param2= 112;
193 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
194 // XCallback::inoutValuesAll
195 param2=120;
196 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
197 //######################################################################
198 // in parameters
199 //######################################################################
200 // XCallback::inValues
201 param2= 200;
202 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
203 // XCallback::inSeqByte
204 // SAFEARRAY( VARIANT)
205 param2= 201;
206 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
207 //XCallback::inSeqXEventListener
208 param2= 202;
209 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
210 //######################################################################
211 // The UNO test component OleTest calls on XCallback_Impl.Callback directly
212 // that is the COM object has not been past a parameter but rather OleTest
213 // creates the COM object itself
214 //######################################################################
215 // XCallback::outValuesAll
216 // does not work currently
217 param2= 300;
218 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
219 // XCallback::inoutValuesAll
220 param2= 301;
221 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
222 // XCallback::inoutValues
223 param2= 302;
224 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
225
226 // XCallback::inValues
227 param2= 303;
228 hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2);
229 //######################################################################
230 // Test a COM object which implements several interfaces.
231 //######################################################################
232
233 CComQIPtr<IDispatch> dispSimple;
234 hr= dispSimple.CoCreateInstance(L"XCallback_Impl.Simple");
235 CComVariant varSimple( dispSimple);
236 param2= 0;
237 hr= oletest.Invoke2(L"testInterface2", &varSimple, ¶m2);
238
239 return hr;
240 }
241 // VARIANT CComVariant VT_UNKNOWN VT_DISPATCH V_UI1 CComDispatchDriver WINAPI
242
243