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 // Callback.cpp : Implementation of CCallback
24cdf0e10cSrcweir #include "stdafx.h"
25cdf0e10cSrcweir #include "XCallback_Impl.h"
26cdf0e10cSrcweir #include "Callback.h"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////
29cdf0e10cSrcweir // CCallback
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
func1()32cdf0e10cSrcweir STDMETHODIMP CCallback::func1()
33cdf0e10cSrcweir {
34cdf0e10cSrcweir 	MessageBox( NULL, _T("Callback::func1 called"),_T(""), MB_OK);
35cdf0e10cSrcweir 	return S_OK;
36cdf0e10cSrcweir }
37cdf0e10cSrcweir 
returnInterface(IDispatch ** ppdisp)38cdf0e10cSrcweir STDMETHODIMP CCallback::returnInterface(IDispatch **ppdisp)
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	if( ! ppdisp)
41cdf0e10cSrcweir 		return E_POINTER;
42cdf0e10cSrcweir 	CComPtr<IDispatch> spDisp;
43cdf0e10cSrcweir 	spDisp.CoCreateInstance( L"XCallback_Impl.Simple");
44cdf0e10cSrcweir 	*ppdisp= spDisp;
45cdf0e10cSrcweir 	(*ppdisp)->AddRef();
46cdf0e10cSrcweir 	return S_OK;
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
outInterface(IDispatch ** ppdisp)49cdf0e10cSrcweir STDMETHODIMP CCallback::outInterface(IDispatch **ppdisp)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir //	return S_OK;
52cdf0e10cSrcweir 	if( ! ppdisp)
53cdf0e10cSrcweir 		return E_POINTER;
54cdf0e10cSrcweir 	CComPtr<IDispatch> spDisp;
55cdf0e10cSrcweir 	spDisp.CoCreateInstance( L"XCallback_Impl.Simple");
56cdf0e10cSrcweir 	*ppdisp= spDisp;
57cdf0e10cSrcweir 	(*ppdisp)->AddRef();
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //	MessageBox( NULL, _T("CCallback::outInterface"), _T(""), MB_OK);
60cdf0e10cSrcweir 	return S_OK;
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
outValuesMixed(long val,long * pval,BSTR string)63cdf0e10cSrcweir STDMETHODIMP CCallback::outValuesMixed(long val, long *pval, BSTR string)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	USES_CONVERSION;
66cdf0e10cSrcweir 	char buff[1024];
67cdf0e10cSrcweir 	*pval = val+1;
68cdf0e10cSrcweir 	sprintf( buff, "param1: %d, param2 out: %d, param3: %S", val, *pval, string);
69cdf0e10cSrcweir 	MessageBox( NULL, A2T(buff), A2T("XCallback_Impl.Callback"), MB_OK);
70cdf0e10cSrcweir 	return S_OK;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
outValuesAll(IDispatch __RPC_FAR * __RPC_FAR * ppdisp,IDispatch __RPC_FAR * __RPC_FAR * ppSimpleStruct,long __RPC_FAR * aSimpleEnum,SAFEARRAY __RPC_FAR * __RPC_FAR * outSeq,VARIANT __RPC_FAR * varAny,VARIANT_BOOL __RPC_FAR * aBool,short __RPC_FAR * aChar,BSTR __RPC_FAR * aString,float __RPC_FAR * aFloat,double __RPC_FAR * aDouble,unsigned char __RPC_FAR * aByte,short __RPC_FAR * aShort,long __RPC_FAR * aLong)74cdf0e10cSrcweir STDMETHODIMP CCallback::outValuesAll(
75cdf0e10cSrcweir             /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdisp,
76cdf0e10cSrcweir             /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppSimpleStruct,
77cdf0e10cSrcweir             /* [out] */ long __RPC_FAR *aSimpleEnum,
78cdf0e10cSrcweir             /* [out] */ SAFEARRAY __RPC_FAR * __RPC_FAR *outSeq,
79cdf0e10cSrcweir             /* [out] */ VARIANT __RPC_FAR *varAny,
80cdf0e10cSrcweir             /* [out] */ VARIANT_BOOL __RPC_FAR *aBool,
81cdf0e10cSrcweir             /* [out] */ short __RPC_FAR *aChar,
82cdf0e10cSrcweir             /* [out] */ BSTR __RPC_FAR *aString,
83cdf0e10cSrcweir             /* [out] */ float __RPC_FAR *aFloat,
84cdf0e10cSrcweir             /* [out] */ double __RPC_FAR *aDouble,
85cdf0e10cSrcweir             /* [out] */  unsigned char __RPC_FAR *aByte,
86cdf0e10cSrcweir             /* [out] */ short __RPC_FAR *aShort,
87cdf0e10cSrcweir             /* [out] */ long __RPC_FAR *aLong)
88cdf0e10cSrcweir //)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir //	if( ! ppdisp || ! ppSimpleStruct || ! aSimpleEnum ||
91cdf0e10cSrcweir //		! outSeq || !varAny ||! aBool || ! aChar ||
92cdf0e10cSrcweir //		! aString || ! aFloat || ! aDouble || ! aByte ||
93cdf0e10cSrcweir //		! aShort || ! aLong || ! aUShort || ! aULong)
94cdf0e10cSrcweir //		return E_POINTER;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	HRESULT hr=S_OK;
97cdf0e10cSrcweir 	hr= outInterface( ppdisp);
98cdf0e10cSrcweir 	hr= outStruct( ppSimpleStruct);
99cdf0e10cSrcweir 	hr= outEnum( aSimpleEnum);
100cdf0e10cSrcweir 	hr= outSeqAny( outSeq);
101cdf0e10cSrcweir 	hr= outAny( varAny);
102cdf0e10cSrcweir 	hr= outBool( aBool);
103cdf0e10cSrcweir 	hr= outChar( aChar);
104cdf0e10cSrcweir 	hr= outString( aString);
105cdf0e10cSrcweir 	hr= outFloat( aFloat);
106cdf0e10cSrcweir 	hr= outDouble( aDouble);
107cdf0e10cSrcweir 	hr= outByte( aByte);
108cdf0e10cSrcweir 	hr= outShort( aShort);
109cdf0e10cSrcweir 	hr= outLong( aLong);
110cdf0e10cSrcweir 	return hr;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
outStruct(IDispatch ** outStruct)113cdf0e10cSrcweir STDMETHODIMP CCallback::outStruct(IDispatch **outStruct)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir //	return S_OK;
116cdf0e10cSrcweir 	if( !outStruct)
117cdf0e10cSrcweir 		return E_POINTER;
118cdf0e10cSrcweir 	HRESULT hr= E_FAIL;
119cdf0e10cSrcweir //	MessageBox( NULL, _T("CCallback::outStruct"), _T(""), MB_OK);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	CComPtr<IDispatch> _dispMgr;
122cdf0e10cSrcweir 	if( SUCCEEDED(hr= _dispMgr.CoCreateInstance(L"com.sun.star.ServiceManager")))
123cdf0e10cSrcweir 	{
124cdf0e10cSrcweir 		CComDispatchDriver manager( _dispMgr);
125cdf0e10cSrcweir 		CComVariant param1(L"com.sun.star.reflection.CoreReflection");
126cdf0e10cSrcweir 		CComVariant varRet;
127cdf0e10cSrcweir 		hr= manager.Invoke1( L"createInstance", &param1, &varRet);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		CComDispatchDriver reflection( varRet.pdispVal);
130cdf0e10cSrcweir 		param1= L"oletest.SimpleStruct";
131cdf0e10cSrcweir 		varRet.Clear();
132cdf0e10cSrcweir 		hr= reflection.Invoke1( L"forName", &param1, &varRet);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 		CComDispatchDriver classSimpleStruct( varRet.pdispVal);
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 		CComPtr<IDispatch> dispStruct;
137cdf0e10cSrcweir 		param1.vt= VT_DISPATCH | VT_BYREF;
138cdf0e10cSrcweir 		param1.ppdispVal= &dispStruct;
139cdf0e10cSrcweir 		if( SUCCEEDED( hr= classSimpleStruct.Invoke1(L"createObject", &param1)))
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir 			// Set the value
142cdf0e10cSrcweir 			CComDispatchDriver simpleStruct( dispStruct);
143cdf0e10cSrcweir 			param1=L" this is a property string";
144cdf0e10cSrcweir 			hr=	simpleStruct.PutPropertyByName(L"message", &param1);
145cdf0e10cSrcweir 			*outStruct= dispStruct;
146cdf0e10cSrcweir 			(*outStruct)->AddRef();
147cdf0e10cSrcweir 			hr= S_OK;
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 	}
150cdf0e10cSrcweir 	return hr;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
outEnum(long * outEnum)153cdf0e10cSrcweir STDMETHODIMP CCallback::outEnum(long *outEnum)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	if( !outEnum)
156cdf0e10cSrcweir 		return E_POINTER;
157cdf0e10cSrcweir 	*outEnum= 1;
158cdf0e10cSrcweir 	return S_OK;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
outSeqAny(LPSAFEARRAY * outSeq)161cdf0e10cSrcweir STDMETHODIMP CCallback::outSeqAny(LPSAFEARRAY* outSeq)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir //	_CrtDbgBreak();
164cdf0e10cSrcweir 	SAFEARRAY* pArr= SafeArrayCreateVector( VT_VARIANT, 0, 3);
165cdf0e10cSrcweir 	CComVariant var[3];
166cdf0e10cSrcweir 	var[0]=L" variant 0";
167cdf0e10cSrcweir 	var[1]=L" variant 1";
168cdf0e10cSrcweir 	var[2]=L"variant 2";
169cdf0e10cSrcweir 	for( long i=0; i<3; i++)
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		SafeArrayPutElement( pArr, &i, (void*)&var[i]);
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	*outSeq= pArr;
175cdf0e10cSrcweir 	return S_OK;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir // ATLASSERT //VT_EMPTY
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
outAny(VARIANT * outAny)181cdf0e10cSrcweir STDMETHODIMP CCallback::outAny(VARIANT *outAny)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir 	if( ! outAny)
184cdf0e10cSrcweir 		return E_POINTER;
185cdf0e10cSrcweir 	outAny->vt= VT_BSTR;
186cdf0e10cSrcweir 	outAny->bstrVal= SysAllocString( L"This is a string in a VARIANT");
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	return S_OK;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
outBool(VARIANT_BOOL * outBool)191cdf0e10cSrcweir STDMETHODIMP CCallback::outBool(VARIANT_BOOL *outBool)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir 	if( ! outBool)
194cdf0e10cSrcweir 		return E_POINTER;
195cdf0e10cSrcweir 	*outBool= VARIANT_TRUE;
196cdf0e10cSrcweir 	return S_OK;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
outChar(short * outChar)199cdf0e10cSrcweir STDMETHODIMP CCallback::outChar(short *outChar)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	if( !outChar)
202cdf0e10cSrcweir 		return E_POINTER;
203cdf0e10cSrcweir 	*outChar= (short)L'A';
204cdf0e10cSrcweir 	return S_OK;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
outString(BSTR * outString)207cdf0e10cSrcweir STDMETHODIMP CCallback::outString(BSTR *outString)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	if( !outString)
210cdf0e10cSrcweir 		return E_POINTER;
211cdf0e10cSrcweir 	*outString= SysAllocString(L"This is a BSTR");
212cdf0e10cSrcweir 	return S_OK;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
outFloat(float * outFloat)215cdf0e10cSrcweir STDMETHODIMP CCallback::outFloat(float *outFloat)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	if( !outFloat)
218cdf0e10cSrcweir 		return E_POINTER;
219cdf0e10cSrcweir 	*outFloat= 3.14f;
220cdf0e10cSrcweir 	return S_OK;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
outDouble(double * outDouble)223cdf0e10cSrcweir STDMETHODIMP CCallback::outDouble(double *outDouble)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	if(!outDouble)
226cdf0e10cSrcweir 		return E_POINTER;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	*outDouble= 3.145;
229cdf0e10cSrcweir 	return S_OK;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 
outShort(short * outShort)234cdf0e10cSrcweir STDMETHODIMP CCallback::outShort(short *outShort)
235cdf0e10cSrcweir {
236cdf0e10cSrcweir 	if(!outShort)
237cdf0e10cSrcweir 		return E_POINTER;
238cdf0e10cSrcweir 	*outShort= -1;
239cdf0e10cSrcweir 	return S_OK;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
outLong(long * outLong)242cdf0e10cSrcweir STDMETHODIMP CCallback::outLong(long *outLong)
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	if(!outLong)
245cdf0e10cSrcweir 		return E_POINTER;
246cdf0e10cSrcweir 	*outLong= 0xffffffff;
247cdf0e10cSrcweir 	return S_OK;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 
outByte(unsigned char * outByte)252cdf0e10cSrcweir STDMETHODIMP CCallback::outByte(unsigned char* outByte)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	if(!outByte)
255cdf0e10cSrcweir 		return E_POINTER;
256cdf0e10cSrcweir 	*outByte= 0xff;
257cdf0e10cSrcweir 	return S_OK;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
inoutInterface(IDispatch ** ppdisp)260cdf0e10cSrcweir STDMETHODIMP CCallback::inoutInterface(IDispatch **ppdisp)
261cdf0e10cSrcweir {
262cdf0e10cSrcweir 	if( !ppdisp)
263cdf0e10cSrcweir 		return E_POINTER;
264cdf0e10cSrcweir 	CComDispatchDriver disp( *ppdisp);
265cdf0e10cSrcweir 	CComVariant param1(L"");
266cdf0e10cSrcweir 	disp.Invoke1(L"func", &param1);
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 	(*ppdisp)->Release();
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	CComPtr<IDispatch> outDisp;
271cdf0e10cSrcweir 	outDisp.CoCreateInstance( L"XCallback_Impl.Simple");
272cdf0e10cSrcweir 	*ppdisp= outDisp;
273cdf0e10cSrcweir 	(*ppdisp)->AddRef();
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 	return S_OK;
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
inoutStruct(IDispatch ** inoutVal)278cdf0e10cSrcweir STDMETHODIMP CCallback::inoutStruct(IDispatch **inoutVal)
279cdf0e10cSrcweir {
280cdf0e10cSrcweir 	if( !inoutVal)
281cdf0e10cSrcweir 		return E_POINTER;
282cdf0e10cSrcweir 	HRESULT hr= S_OK;
283cdf0e10cSrcweir 	USES_CONVERSION;
284cdf0e10cSrcweir 	CComVariant var;
285cdf0e10cSrcweir 	CComDispatchDriver disp( *inoutVal);
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	hr= disp.GetPropertyByName(L"message", &var);
288cdf0e10cSrcweir 	MessageBox( NULL, W2T(var.bstrVal), _T("XCallback_Impl.Callback"), MB_OK);
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	(*inoutVal)->Release();
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	CComDispatchDriver dispStruct;
293cdf0e10cSrcweir 	hr= outStruct( &dispStruct.p);
294cdf0e10cSrcweir 	var.Clear();
295cdf0e10cSrcweir 	var= L"This struct was created in XCallback_Imp.Callback";
296cdf0e10cSrcweir 	hr=	dispStruct.PutPropertyByName(L"message", &var);
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	*inoutVal= dispStruct;
299cdf0e10cSrcweir 	(*inoutVal)->AddRef();
300cdf0e10cSrcweir 	return hr;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
inoutEnum(long * inoutVal)303cdf0e10cSrcweir STDMETHODIMP CCallback::inoutEnum(long *inoutVal)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir 	if( !inoutVal)
306cdf0e10cSrcweir 		return E_POINTER;
307cdf0e10cSrcweir 	*inoutVal= *inoutVal+1;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 	return S_OK;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
inoutSeqAny(LPSAFEARRAY * pArray)312cdf0e10cSrcweir STDMETHODIMP CCallback::inoutSeqAny(LPSAFEARRAY *pArray)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir 	if( !pArray)
315cdf0e10cSrcweir 		return E_POINTER;
316cdf0e10cSrcweir 	HRESULT hr= S_OK;
317cdf0e10cSrcweir 	long lbound=0;
318cdf0e10cSrcweir 	long ubound=0;
319cdf0e10cSrcweir 	hr= SafeArrayGetLBound( *pArray, 1, &lbound);
320cdf0e10cSrcweir 	hr= SafeArrayGetUBound( *pArray, 1, &ubound);
321cdf0e10cSrcweir 	long count= ubound - lbound + 1;
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 	// the Array is supposet to contain variants
324cdf0e10cSrcweir 	CComVariant var;
325cdf0e10cSrcweir 	for( long i=0; i<count; i++)
326cdf0e10cSrcweir 	{
327cdf0e10cSrcweir 		var.Clear();
328cdf0e10cSrcweir 		hr= SafeArrayGetElement( *pArray, &i, (void*)&var);
329cdf0e10cSrcweir 	}
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 	SafeArrayDestroy( *pArray);
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	outSeqAny( pArray);
334cdf0e10cSrcweir 	return S_OK;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
inoutAny(VARIANT * inoutVal)337cdf0e10cSrcweir STDMETHODIMP CCallback::inoutAny(VARIANT *inoutVal)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir 	if( !inoutVal)
340cdf0e10cSrcweir 		return E_POINTER;
341cdf0e10cSrcweir 	USES_CONVERSION;
342cdf0e10cSrcweir 	if( inoutVal->vt= VT_BSTR)
343cdf0e10cSrcweir 		MessageBox( NULL, W2T( inoutVal->bstrVal), _T("XCallback_Impl.Callback"), MB_OK);
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 	VariantClear( inoutVal);
346cdf0e10cSrcweir 	inoutVal->vt= VT_BSTR;
347cdf0e10cSrcweir 	inoutVal->bstrVal=SysAllocString( L" [string] XCallback_Impl.Callback inoutAny");
348cdf0e10cSrcweir 	return S_OK;
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
inoutBool(VARIANT_BOOL * inoutVal)351cdf0e10cSrcweir STDMETHODIMP CCallback::inoutBool(VARIANT_BOOL *inoutVal)
352cdf0e10cSrcweir {
353cdf0e10cSrcweir 	if( !inoutVal)
354cdf0e10cSrcweir 		return E_POINTER;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	*inoutVal= *inoutVal == VARIANT_TRUE ? VARIANT_FALSE : VARIANT_TRUE;
357cdf0e10cSrcweir 	return S_OK;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
inoutChar(short * inoutVal)360cdf0e10cSrcweir STDMETHODIMP CCallback::inoutChar(short *inoutVal)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir 	if( !inoutVal)
363cdf0e10cSrcweir 		return E_POINTER;
364cdf0e10cSrcweir 	USES_CONVERSION;
365cdf0e10cSrcweir 	char buff[256];
366cdf0e10cSrcweir 	sprintf( buff, "character value: %C", *inoutVal);
367cdf0e10cSrcweir 	MessageBox( NULL, A2T(buff), _T("XCallback_Impl.Callback"), MB_OK);
368cdf0e10cSrcweir 	*inoutVal= L'B';
369cdf0e10cSrcweir 	return S_OK;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
inoutString(BSTR * inoutVal)372cdf0e10cSrcweir STDMETHODIMP CCallback::inoutString(BSTR *inoutVal)
373cdf0e10cSrcweir {
374cdf0e10cSrcweir 	if( !inoutVal)
375cdf0e10cSrcweir 		return E_POINTER;
376cdf0e10cSrcweir 	USES_CONVERSION;
377cdf0e10cSrcweir 	MessageBox( NULL, W2T(*inoutVal), _T("XCallback_Impl.Callback"), MB_OK);
378cdf0e10cSrcweir 	SysFreeString(*inoutVal);
379cdf0e10cSrcweir 	*inoutVal= SysAllocString(L"a string from XCallback_Impl.Callback");
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 	return S_OK;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
inoutFloat(float * inoutVal)384cdf0e10cSrcweir STDMETHODIMP CCallback::inoutFloat(float *inoutVal)
385cdf0e10cSrcweir {
386cdf0e10cSrcweir 	if( !inoutVal)
387cdf0e10cSrcweir 		return E_POINTER;
388cdf0e10cSrcweir 	*inoutVal = *inoutVal+1;
389cdf0e10cSrcweir 	return S_OK;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
inoutDouble(double * inoutVal)392cdf0e10cSrcweir STDMETHODIMP CCallback::inoutDouble(double *inoutVal)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir 	if( !inoutVal)
395cdf0e10cSrcweir 		return E_POINTER;
396cdf0e10cSrcweir 	*inoutVal= *inoutVal+1;
397cdf0e10cSrcweir 	return S_OK;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir 
inoutByte(unsigned char * inoutVal)400cdf0e10cSrcweir STDMETHODIMP CCallback::inoutByte(unsigned char *inoutVal)
401cdf0e10cSrcweir {
402cdf0e10cSrcweir 	if( !inoutVal)
403cdf0e10cSrcweir 		return E_POINTER;
404cdf0e10cSrcweir 	*inoutVal= 0xff;
405cdf0e10cSrcweir 	return S_OK;
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
inoutShort(short * inoutVal)408cdf0e10cSrcweir STDMETHODIMP CCallback::inoutShort(short *inoutVal)
409cdf0e10cSrcweir {
410cdf0e10cSrcweir 	if( !inoutVal)
411cdf0e10cSrcweir 		return E_POINTER;
412cdf0e10cSrcweir 	*inoutVal= -1;
413cdf0e10cSrcweir 	return S_OK;
414cdf0e10cSrcweir }
415cdf0e10cSrcweir 
inoutLong(long * inoutVal)416cdf0e10cSrcweir STDMETHODIMP CCallback::inoutLong(long* inoutVal)
417cdf0e10cSrcweir {
418cdf0e10cSrcweir 	if( !inoutVal)
419cdf0e10cSrcweir 		return E_POINTER;
420cdf0e10cSrcweir 	*inoutVal= 0xffffffff;
421cdf0e10cSrcweir 	return S_OK;
422cdf0e10cSrcweir }
423cdf0e10cSrcweir 
inoutValuesAll(IDispatch __RPC_FAR * __RPC_FAR * aXSimple,IDispatch __RPC_FAR * __RPC_FAR * aStruct,long __RPC_FAR * aEnum,SAFEARRAY __RPC_FAR * __RPC_FAR * aSeq,VARIANT __RPC_FAR * aAny,VARIANT_BOOL __RPC_FAR * aBool,short __RPC_FAR * aChar,BSTR __RPC_FAR * aString,float __RPC_FAR * aFloat,double __RPC_FAR * aDouble,unsigned char __RPC_FAR * aByte,short __RPC_FAR * aShort,long __RPC_FAR * aLong)424cdf0e10cSrcweir STDMETHODIMP CCallback::inoutValuesAll(
425cdf0e10cSrcweir             /* [out][in] */ IDispatch __RPC_FAR *__RPC_FAR *aXSimple,
426cdf0e10cSrcweir             /* [out][in] */ IDispatch __RPC_FAR *__RPC_FAR *aStruct,
427cdf0e10cSrcweir             /* [out][in] */ long __RPC_FAR *aEnum,
428cdf0e10cSrcweir             /* [out][in] */ SAFEARRAY __RPC_FAR * __RPC_FAR *aSeq,
429cdf0e10cSrcweir             /* [out][in] */ VARIANT __RPC_FAR *aAny,
430cdf0e10cSrcweir             /* [out][in] */ VARIANT_BOOL __RPC_FAR *aBool,
431cdf0e10cSrcweir             /* [out][in] */ short __RPC_FAR *aChar,
432cdf0e10cSrcweir             /* [out][in] */ BSTR __RPC_FAR *aString,
433cdf0e10cSrcweir             /* [out][in] */ float __RPC_FAR *aFloat,
434cdf0e10cSrcweir             /* [out][in] */ double __RPC_FAR *aDouble,
435cdf0e10cSrcweir             /* [out][in] */ unsigned char __RPC_FAR *aByte,
436cdf0e10cSrcweir             /* [out][in] */ short __RPC_FAR *aShort,
437cdf0e10cSrcweir             /* [out][in] */ long __RPC_FAR *aLong)
438cdf0e10cSrcweir {
439cdf0e10cSrcweir 	inoutInterface( aXSimple);
440cdf0e10cSrcweir 	inoutStruct( aStruct);
441cdf0e10cSrcweir 	inoutEnum( aEnum);
442cdf0e10cSrcweir 	inoutSeqAny( aSeq);
443cdf0e10cSrcweir 	inoutAny( aAny);
444cdf0e10cSrcweir 	inoutBool( aBool);
445cdf0e10cSrcweir 	inoutChar( aChar);
446cdf0e10cSrcweir 	inoutString( aString);
447cdf0e10cSrcweir 	inoutFloat( aFloat);
448cdf0e10cSrcweir 	inoutDouble( aDouble);
449cdf0e10cSrcweir 	inoutByte( aByte);
450cdf0e10cSrcweir 	inoutShort( aShort);
451cdf0e10cSrcweir 	inoutLong( aLong);
452cdf0e10cSrcweir 
453cdf0e10cSrcweir 	return S_OK;
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 
inValues(short aChar,long aLong,BSTR aString)457cdf0e10cSrcweir STDMETHODIMP CCallback::inValues(short aChar, long aLong, BSTR aString)
458cdf0e10cSrcweir {
459cdf0e10cSrcweir 	USES_CONVERSION;
460cdf0e10cSrcweir 	wchar_t _char= (wchar_t) aChar;
461cdf0e10cSrcweir 	char buff[1024];
462cdf0e10cSrcweir 	sprintf( buff, "Parameters: char= %C, long= %d, string= %s", _char, aLong, W2A(aString));
463cdf0e10cSrcweir 	MessageBox( NULL, A2T(buff), _T("XCallback_Impl.Callback"), MB_OK);
464cdf0e10cSrcweir 	return S_OK;
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
outSeqByte(LPSAFEARRAY * outVal)467cdf0e10cSrcweir STDMETHODIMP CCallback::outSeqByte(LPSAFEARRAY * outVal)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir 	// TODO: Add your implementation code here
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	return S_OK;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
inSeqByte(LPSAFEARRAY listeners)474cdf0e10cSrcweir STDMETHODIMP CCallback::inSeqByte( LPSAFEARRAY listeners)
475cdf0e10cSrcweir {
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 	return S_OK;
478cdf0e10cSrcweir }
479cdf0e10cSrcweir 
inSeqXEventListener(LPSAFEARRAY listeners,LPSAFEARRAY events)480cdf0e10cSrcweir STDMETHODIMP CCallback::inSeqXEventListener( LPSAFEARRAY listeners, LPSAFEARRAY events)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir 	HRESULT hr= S_OK;
483cdf0e10cSrcweir 	long ubound= 0;
484cdf0e10cSrcweir 	long lbound= 0;
485cdf0e10cSrcweir 	long count= 0;
486cdf0e10cSrcweir 	hr= SafeArrayGetUBound( listeners, 1, &ubound);
487cdf0e10cSrcweir 	hr= SafeArrayGetLBound( listeners, 1, &lbound);
488cdf0e10cSrcweir 	count= ubound - lbound +1;
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 	// We assume thate the count of EventObjects in events is the same
491cdf0e10cSrcweir 	for( long i = 0; i < count; i++)
492cdf0e10cSrcweir 	{
493cdf0e10cSrcweir 		CComVariant varListener;
494cdf0e10cSrcweir 		CComVariant varEvent;
495cdf0e10cSrcweir 		hr= SafeArrayGetElement( listeners, &i, &varListener);
496cdf0e10cSrcweir 		hr= SafeArrayGetElement( events, &i, &varEvent);
497cdf0e10cSrcweir 		if( varListener.vt == VT_DISPATCH && varEvent.vt == VT_DISPATCH)
498cdf0e10cSrcweir 		{
499cdf0e10cSrcweir 			CComDispatchDriver disp( varListener.pdispVal);
500cdf0e10cSrcweir 			hr= disp.Invoke1(L"disposing", &varEvent);
501cdf0e10cSrcweir 		}
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 	}
504cdf0e10cSrcweir 
505cdf0e10cSrcweir 	return S_OK;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 
509