1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Callback.cpp,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 // Callback.cpp : Implementation of CCallback
32 #include "XCallback_Impl.h"
35 /////////////////////////////////////////////////////////////////////////////
39 STDMETHODIMP
CCallback::func1()
41 MessageBox( NULL
, _T("Callback::func1 called"),_T(""), MB_OK
);
45 STDMETHODIMP
CCallback::returnInterface(IDispatch
**ppdisp
)
49 CComPtr
<IDispatch
> spDisp
;
50 spDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
56 STDMETHODIMP
CCallback::outInterface(IDispatch
**ppdisp
)
61 CComPtr
<IDispatch
> spDisp
;
62 spDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
66 // MessageBox( NULL, _T("CCallback::outInterface"), _T(""), MB_OK);
70 STDMETHODIMP
CCallback::outValuesMixed(long val
, long *pval
, BSTR string
)
75 sprintf( buff
, "param1: %d, param2 out: %d, param3: %S", val
, *pval
, string
);
76 MessageBox( NULL
, A2T(buff
), A2T("XCallback_Impl.Callback"), MB_OK
);
81 STDMETHODIMP
CCallback::outValuesAll(
82 /* [out] */ IDispatch __RPC_FAR
*__RPC_FAR
*ppdisp
,
83 /* [out] */ IDispatch __RPC_FAR
*__RPC_FAR
*ppSimpleStruct
,
84 /* [out] */ long __RPC_FAR
*aSimpleEnum
,
85 /* [out] */ SAFEARRAY __RPC_FAR
* __RPC_FAR
*outSeq
,
86 /* [out] */ VARIANT __RPC_FAR
*varAny
,
87 /* [out] */ VARIANT_BOOL __RPC_FAR
*aBool
,
88 /* [out] */ short __RPC_FAR
*aChar
,
89 /* [out] */ BSTR __RPC_FAR
*aString
,
90 /* [out] */ float __RPC_FAR
*aFloat
,
91 /* [out] */ double __RPC_FAR
*aDouble
,
92 /* [out] */ unsigned char __RPC_FAR
*aByte
,
93 /* [out] */ short __RPC_FAR
*aShort
,
94 /* [out] */ long __RPC_FAR
*aLong
)
97 // if( ! ppdisp || ! ppSimpleStruct || ! aSimpleEnum ||
98 // ! outSeq || !varAny ||! aBool || ! aChar ||
99 // ! aString || ! aFloat || ! aDouble || ! aByte ||
100 // ! aShort || ! aLong || ! aUShort || ! aULong)
104 hr
= outInterface( ppdisp
);
105 hr
= outStruct( ppSimpleStruct
);
106 hr
= outEnum( aSimpleEnum
);
107 hr
= outSeqAny( outSeq
);
111 hr
= outString( aString
);
112 hr
= outFloat( aFloat
);
113 hr
= outDouble( aDouble
);
115 hr
= outShort( aShort
);
120 STDMETHODIMP
CCallback::outStruct(IDispatch
**outStruct
)
126 // MessageBox( NULL, _T("CCallback::outStruct"), _T(""), MB_OK);
128 CComPtr
<IDispatch
> _dispMgr
;
129 if( SUCCEEDED(hr
= _dispMgr
.CoCreateInstance(L
"com.sun.star.ServiceManager")))
131 CComDispatchDriver
manager( _dispMgr
);
132 CComVariant
param1(L
"com.sun.star.reflection.CoreReflection");
134 hr
= manager
.Invoke1( L
"createInstance", ¶m1
, &varRet
);
136 CComDispatchDriver
reflection( varRet
.pdispVal
);
137 param1
= L
"oletest.SimpleStruct";
139 hr
= reflection
.Invoke1( L
"forName", ¶m1
, &varRet
);
141 CComDispatchDriver
classSimpleStruct( varRet
.pdispVal
);
143 CComPtr
<IDispatch
> dispStruct
;
144 param1
.vt
= VT_DISPATCH
| VT_BYREF
;
145 param1
.ppdispVal
= &dispStruct
;
146 if( SUCCEEDED( hr
= classSimpleStruct
.Invoke1(L
"createObject", ¶m1
)))
149 CComDispatchDriver
simpleStruct( dispStruct
);
150 param1
=L
" this is a property string";
151 hr
= simpleStruct
.PutPropertyByName(L
"message", ¶m1
);
152 *outStruct
= dispStruct
;
153 (*outStruct
)->AddRef();
160 STDMETHODIMP
CCallback::outEnum(long *outEnum
)
168 STDMETHODIMP
CCallback::outSeqAny(LPSAFEARRAY
* outSeq
)
171 SAFEARRAY
* pArr
= SafeArrayCreateVector( VT_VARIANT
, 0, 3);
173 var
[0]=L
" variant 0";
174 var
[1]=L
" variant 1";
176 for( long i
=0; i
<3; i
++)
178 SafeArrayPutElement( pArr
, &i
, (void*)&var
[i
]);
185 // ATLASSERT //VT_EMPTY
188 STDMETHODIMP
CCallback::outAny(VARIANT
*outAny
)
193 outAny
->bstrVal
= SysAllocString( L
"This is a string in a VARIANT");
198 STDMETHODIMP
CCallback::outBool(VARIANT_BOOL
*outBool
)
202 *outBool
= VARIANT_TRUE
;
206 STDMETHODIMP
CCallback::outChar(short *outChar
)
210 *outChar
= (short)L
'A';
214 STDMETHODIMP
CCallback::outString(BSTR
*outString
)
218 *outString
= SysAllocString(L
"This is a BSTR");
222 STDMETHODIMP
CCallback::outFloat(float *outFloat
)
230 STDMETHODIMP
CCallback::outDouble(double *outDouble
)
241 STDMETHODIMP
CCallback::outShort(short *outShort
)
249 STDMETHODIMP
CCallback::outLong(long *outLong
)
253 *outLong
= 0xffffffff;
259 STDMETHODIMP
CCallback::outByte(unsigned char* outByte
)
267 STDMETHODIMP
CCallback::inoutInterface(IDispatch
**ppdisp
)
271 CComDispatchDriver
disp( *ppdisp
);
272 CComVariant
param1(L
"");
273 disp
.Invoke1(L
"func", ¶m1
);
275 (*ppdisp
)->Release();
277 CComPtr
<IDispatch
> outDisp
;
278 outDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
285 STDMETHODIMP
CCallback::inoutStruct(IDispatch
**inoutVal
)
292 CComDispatchDriver
disp( *inoutVal
);
294 hr
= disp
.GetPropertyByName(L
"message", &var
);
295 MessageBox( NULL
, W2T(var
.bstrVal
), _T("XCallback_Impl.Callback"), MB_OK
);
297 (*inoutVal
)->Release();
299 CComDispatchDriver dispStruct
;
300 hr
= outStruct( &dispStruct
.p
);
302 var
= L
"This struct was created in XCallback_Imp.Callback";
303 hr
= dispStruct
.PutPropertyByName(L
"message", &var
);
305 *inoutVal
= dispStruct
;
306 (*inoutVal
)->AddRef();
310 STDMETHODIMP
CCallback::inoutEnum(long *inoutVal
)
314 *inoutVal
= *inoutVal
+1;
319 STDMETHODIMP
CCallback::inoutSeqAny(LPSAFEARRAY
*pArray
)
326 hr
= SafeArrayGetLBound( *pArray
, 1, &lbound
);
327 hr
= SafeArrayGetUBound( *pArray
, 1, &ubound
);
328 long count
= ubound
- lbound
+ 1;
330 // the Array is supposet to contain variants
332 for( long i
=0; i
<count
; i
++)
335 hr
= SafeArrayGetElement( *pArray
, &i
, (void*)&var
);
338 SafeArrayDestroy( *pArray
);
344 STDMETHODIMP
CCallback::inoutAny(VARIANT
*inoutVal
)
349 if( inoutVal
->vt
= VT_BSTR
)
350 MessageBox( NULL
, W2T( inoutVal
->bstrVal
), _T("XCallback_Impl.Callback"), MB_OK
);
352 VariantClear( inoutVal
);
353 inoutVal
->vt
= VT_BSTR
;
354 inoutVal
->bstrVal
=SysAllocString( L
" [string] XCallback_Impl.Callback inoutAny");
358 STDMETHODIMP
CCallback::inoutBool(VARIANT_BOOL
*inoutVal
)
363 *inoutVal
= *inoutVal
== VARIANT_TRUE
? VARIANT_FALSE
: VARIANT_TRUE
;
367 STDMETHODIMP
CCallback::inoutChar(short *inoutVal
)
373 sprintf( buff
, "character value: %C", *inoutVal
);
374 MessageBox( NULL
, A2T(buff
), _T("XCallback_Impl.Callback"), MB_OK
);
379 STDMETHODIMP
CCallback::inoutString(BSTR
*inoutVal
)
384 MessageBox( NULL
, W2T(*inoutVal
), _T("XCallback_Impl.Callback"), MB_OK
);
385 SysFreeString(*inoutVal
);
386 *inoutVal
= SysAllocString(L
"a string from XCallback_Impl.Callback");
391 STDMETHODIMP
CCallback::inoutFloat(float *inoutVal
)
395 *inoutVal
= *inoutVal
+1;
399 STDMETHODIMP
CCallback::inoutDouble(double *inoutVal
)
403 *inoutVal
= *inoutVal
+1;
407 STDMETHODIMP
CCallback::inoutByte(unsigned char *inoutVal
)
415 STDMETHODIMP
CCallback::inoutShort(short *inoutVal
)
423 STDMETHODIMP
CCallback::inoutLong(long* inoutVal
)
427 *inoutVal
= 0xffffffff;
431 STDMETHODIMP
CCallback::inoutValuesAll(
432 /* [out][in] */ IDispatch __RPC_FAR
*__RPC_FAR
*aXSimple
,
433 /* [out][in] */ IDispatch __RPC_FAR
*__RPC_FAR
*aStruct
,
434 /* [out][in] */ long __RPC_FAR
*aEnum
,
435 /* [out][in] */ SAFEARRAY __RPC_FAR
* __RPC_FAR
*aSeq
,
436 /* [out][in] */ VARIANT __RPC_FAR
*aAny
,
437 /* [out][in] */ VARIANT_BOOL __RPC_FAR
*aBool
,
438 /* [out][in] */ short __RPC_FAR
*aChar
,
439 /* [out][in] */ BSTR __RPC_FAR
*aString
,
440 /* [out][in] */ float __RPC_FAR
*aFloat
,
441 /* [out][in] */ double __RPC_FAR
*aDouble
,
442 /* [out][in] */ unsigned char __RPC_FAR
*aByte
,
443 /* [out][in] */ short __RPC_FAR
*aShort
,
444 /* [out][in] */ long __RPC_FAR
*aLong
)
446 inoutInterface( aXSimple
);
447 inoutStruct( aStruct
);
453 inoutString( aString
);
455 inoutDouble( aDouble
);
464 STDMETHODIMP
CCallback::inValues(short aChar
, long aLong
, BSTR aString
)
467 wchar_t _char
= (wchar_t) aChar
;
469 sprintf( buff
, "Parameters: char= %C, long= %d, string= %s", _char
, aLong
, W2A(aString
));
470 MessageBox( NULL
, A2T(buff
), _T("XCallback_Impl.Callback"), MB_OK
);
474 STDMETHODIMP
CCallback::outSeqByte(LPSAFEARRAY
* outVal
)
476 // TODO: Add your implementation code here
481 STDMETHODIMP
CCallback::inSeqByte( LPSAFEARRAY listeners
)
487 STDMETHODIMP
CCallback::inSeqXEventListener( LPSAFEARRAY listeners
, LPSAFEARRAY events
)
493 hr
= SafeArrayGetUBound( listeners
, 1, &ubound
);
494 hr
= SafeArrayGetLBound( listeners
, 1, &lbound
);
495 count
= ubound
- lbound
+1;
497 // We assume thate the count of EventObjects in events is the same
498 for( long i
= 0; i
< count
; i
++)
500 CComVariant varListener
;
501 CComVariant varEvent
;
502 hr
= SafeArrayGetElement( listeners
, &i
, &varListener
);
503 hr
= SafeArrayGetElement( events
, &i
, &varEvent
);
504 if( varListener
.vt
== VT_DISPATCH
&& varEvent
.vt
== VT_DISPATCH
)
506 CComDispatchDriver
disp( varListener
.pdispVal
);
507 hr
= disp
.Invoke1(L
"disposing", &varEvent
);