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