1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
27 // Callback.cpp : Implementation of CCallback
29 #include "XCallback_Impl.h"
32 /////////////////////////////////////////////////////////////////////////////
36 STDMETHODIMP
CCallback::func1()
38 MessageBox( NULL
, _T("Callback::func1 called"),_T(""), MB_OK
);
42 STDMETHODIMP
CCallback::returnInterface(IDispatch
**ppdisp
)
46 CComPtr
<IDispatch
> spDisp
;
47 spDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
53 STDMETHODIMP
CCallback::outInterface(IDispatch
**ppdisp
)
58 CComPtr
<IDispatch
> spDisp
;
59 spDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
63 // MessageBox( NULL, _T("CCallback::outInterface"), _T(""), MB_OK);
67 STDMETHODIMP
CCallback::outValuesMixed(long val
, long *pval
, BSTR string
)
72 sprintf( buff
, "param1: %d, param2 out: %d, param3: %S", val
, *pval
, string
);
73 MessageBox( NULL
, A2T(buff
), A2T("XCallback_Impl.Callback"), MB_OK
);
78 STDMETHODIMP
CCallback::outValuesAll(
79 /* [out] */ IDispatch __RPC_FAR
*__RPC_FAR
*ppdisp
,
80 /* [out] */ IDispatch __RPC_FAR
*__RPC_FAR
*ppSimpleStruct
,
81 /* [out] */ long __RPC_FAR
*aSimpleEnum
,
82 /* [out] */ SAFEARRAY __RPC_FAR
* __RPC_FAR
*outSeq
,
83 /* [out] */ VARIANT __RPC_FAR
*varAny
,
84 /* [out] */ VARIANT_BOOL __RPC_FAR
*aBool
,
85 /* [out] */ short __RPC_FAR
*aChar
,
86 /* [out] */ BSTR __RPC_FAR
*aString
,
87 /* [out] */ float __RPC_FAR
*aFloat
,
88 /* [out] */ double __RPC_FAR
*aDouble
,
89 /* [out] */ unsigned char __RPC_FAR
*aByte
,
90 /* [out] */ short __RPC_FAR
*aShort
,
91 /* [out] */ long __RPC_FAR
*aLong
)
94 // if( ! ppdisp || ! ppSimpleStruct || ! aSimpleEnum ||
95 // ! outSeq || !varAny ||! aBool || ! aChar ||
96 // ! aString || ! aFloat || ! aDouble || ! aByte ||
97 // ! aShort || ! aLong || ! aUShort || ! aULong)
101 hr
= outInterface( ppdisp
);
102 hr
= outStruct( ppSimpleStruct
);
103 hr
= outEnum( aSimpleEnum
);
104 hr
= outSeqAny( outSeq
);
108 hr
= outString( aString
);
109 hr
= outFloat( aFloat
);
110 hr
= outDouble( aDouble
);
112 hr
= outShort( aShort
);
117 STDMETHODIMP
CCallback::outStruct(IDispatch
**outStruct
)
123 // MessageBox( NULL, _T("CCallback::outStruct"), _T(""), MB_OK);
125 CComPtr
<IDispatch
> _dispMgr
;
126 if( SUCCEEDED(hr
= _dispMgr
.CoCreateInstance(L
"com.sun.star.ServiceManager")))
128 CComDispatchDriver
manager( _dispMgr
);
129 CComVariant
param1(L
"com.sun.star.reflection.CoreReflection");
131 hr
= manager
.Invoke1( L
"createInstance", ¶m1
, &varRet
);
133 CComDispatchDriver
reflection( varRet
.pdispVal
);
134 param1
= L
"oletest.SimpleStruct";
136 hr
= reflection
.Invoke1( L
"forName", ¶m1
, &varRet
);
138 CComDispatchDriver
classSimpleStruct( varRet
.pdispVal
);
140 CComPtr
<IDispatch
> dispStruct
;
141 param1
.vt
= VT_DISPATCH
| VT_BYREF
;
142 param1
.ppdispVal
= &dispStruct
;
143 if( SUCCEEDED( hr
= classSimpleStruct
.Invoke1(L
"createObject", ¶m1
)))
146 CComDispatchDriver
simpleStruct( dispStruct
);
147 param1
=L
" this is a property string";
148 hr
= simpleStruct
.PutPropertyByName(L
"message", ¶m1
);
149 *outStruct
= dispStruct
;
150 (*outStruct
)->AddRef();
157 STDMETHODIMP
CCallback::outEnum(long *outEnum
)
165 STDMETHODIMP
CCallback::outSeqAny(LPSAFEARRAY
* outSeq
)
168 SAFEARRAY
* pArr
= SafeArrayCreateVector( VT_VARIANT
, 0, 3);
170 var
[0]=L
" variant 0";
171 var
[1]=L
" variant 1";
173 for( long i
=0; i
<3; i
++)
175 SafeArrayPutElement( pArr
, &i
, (void*)&var
[i
]);
182 // ATLASSERT //VT_EMPTY
185 STDMETHODIMP
CCallback::outAny(VARIANT
*outAny
)
190 outAny
->bstrVal
= SysAllocString( L
"This is a string in a VARIANT");
195 STDMETHODIMP
CCallback::outBool(VARIANT_BOOL
*outBool
)
199 *outBool
= VARIANT_TRUE
;
203 STDMETHODIMP
CCallback::outChar(short *outChar
)
207 *outChar
= (short)L
'A';
211 STDMETHODIMP
CCallback::outString(BSTR
*outString
)
215 *outString
= SysAllocString(L
"This is a BSTR");
219 STDMETHODIMP
CCallback::outFloat(float *outFloat
)
227 STDMETHODIMP
CCallback::outDouble(double *outDouble
)
238 STDMETHODIMP
CCallback::outShort(short *outShort
)
246 STDMETHODIMP
CCallback::outLong(long *outLong
)
250 *outLong
= 0xffffffff;
256 STDMETHODIMP
CCallback::outByte(unsigned char* outByte
)
264 STDMETHODIMP
CCallback::inoutInterface(IDispatch
**ppdisp
)
268 CComDispatchDriver
disp( *ppdisp
);
269 CComVariant
param1(L
"");
270 disp
.Invoke1(L
"func", ¶m1
);
272 (*ppdisp
)->Release();
274 CComPtr
<IDispatch
> outDisp
;
275 outDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
282 STDMETHODIMP
CCallback::inoutStruct(IDispatch
**inoutVal
)
289 CComDispatchDriver
disp( *inoutVal
);
291 hr
= disp
.GetPropertyByName(L
"message", &var
);
292 MessageBox( NULL
, W2T(var
.bstrVal
), _T("XCallback_Impl.Callback"), MB_OK
);
294 (*inoutVal
)->Release();
296 CComDispatchDriver dispStruct
;
297 hr
= outStruct( &dispStruct
.p
);
299 var
= L
"This struct was created in XCallback_Imp.Callback";
300 hr
= dispStruct
.PutPropertyByName(L
"message", &var
);
302 *inoutVal
= dispStruct
;
303 (*inoutVal
)->AddRef();
307 STDMETHODIMP
CCallback::inoutEnum(long *inoutVal
)
311 *inoutVal
= *inoutVal
+1;
316 STDMETHODIMP
CCallback::inoutSeqAny(LPSAFEARRAY
*pArray
)
323 hr
= SafeArrayGetLBound( *pArray
, 1, &lbound
);
324 hr
= SafeArrayGetUBound( *pArray
, 1, &ubound
);
325 long count
= ubound
- lbound
+ 1;
327 // the Array is supposet to contain variants
329 for( long i
=0; i
<count
; i
++)
332 hr
= SafeArrayGetElement( *pArray
, &i
, (void*)&var
);
335 SafeArrayDestroy( *pArray
);
341 STDMETHODIMP
CCallback::inoutAny(VARIANT
*inoutVal
)
346 if( inoutVal
->vt
= VT_BSTR
)
347 MessageBox( NULL
, W2T( inoutVal
->bstrVal
), _T("XCallback_Impl.Callback"), MB_OK
);
349 VariantClear( inoutVal
);
350 inoutVal
->vt
= VT_BSTR
;
351 inoutVal
->bstrVal
=SysAllocString( L
" [string] XCallback_Impl.Callback inoutAny");
355 STDMETHODIMP
CCallback::inoutBool(VARIANT_BOOL
*inoutVal
)
360 *inoutVal
= *inoutVal
== VARIANT_TRUE
? VARIANT_FALSE
: VARIANT_TRUE
;
364 STDMETHODIMP
CCallback::inoutChar(short *inoutVal
)
370 sprintf( buff
, "character value: %C", *inoutVal
);
371 MessageBox( NULL
, A2T(buff
), _T("XCallback_Impl.Callback"), MB_OK
);
376 STDMETHODIMP
CCallback::inoutString(BSTR
*inoutVal
)
381 MessageBox( NULL
, W2T(*inoutVal
), _T("XCallback_Impl.Callback"), MB_OK
);
382 SysFreeString(*inoutVal
);
383 *inoutVal
= SysAllocString(L
"a string from XCallback_Impl.Callback");
388 STDMETHODIMP
CCallback::inoutFloat(float *inoutVal
)
392 *inoutVal
= *inoutVal
+1;
396 STDMETHODIMP
CCallback::inoutDouble(double *inoutVal
)
400 *inoutVal
= *inoutVal
+1;
404 STDMETHODIMP
CCallback::inoutByte(unsigned char *inoutVal
)
412 STDMETHODIMP
CCallback::inoutShort(short *inoutVal
)
420 STDMETHODIMP
CCallback::inoutLong(long* inoutVal
)
424 *inoutVal
= 0xffffffff;
428 STDMETHODIMP
CCallback::inoutValuesAll(
429 /* [out][in] */ IDispatch __RPC_FAR
*__RPC_FAR
*aXSimple
,
430 /* [out][in] */ IDispatch __RPC_FAR
*__RPC_FAR
*aStruct
,
431 /* [out][in] */ long __RPC_FAR
*aEnum
,
432 /* [out][in] */ SAFEARRAY __RPC_FAR
* __RPC_FAR
*aSeq
,
433 /* [out][in] */ VARIANT __RPC_FAR
*aAny
,
434 /* [out][in] */ VARIANT_BOOL __RPC_FAR
*aBool
,
435 /* [out][in] */ short __RPC_FAR
*aChar
,
436 /* [out][in] */ BSTR __RPC_FAR
*aString
,
437 /* [out][in] */ float __RPC_FAR
*aFloat
,
438 /* [out][in] */ double __RPC_FAR
*aDouble
,
439 /* [out][in] */ unsigned char __RPC_FAR
*aByte
,
440 /* [out][in] */ short __RPC_FAR
*aShort
,
441 /* [out][in] */ long __RPC_FAR
*aLong
)
443 inoutInterface( aXSimple
);
444 inoutStruct( aStruct
);
450 inoutString( aString
);
452 inoutDouble( aDouble
);
461 STDMETHODIMP
CCallback::inValues(short aChar
, long aLong
, BSTR aString
)
464 wchar_t _char
= (wchar_t) aChar
;
466 sprintf( buff
, "Parameters: char= %C, long= %d, string= %s", _char
, aLong
, W2A(aString
));
467 MessageBox( NULL
, A2T(buff
), _T("XCallback_Impl.Callback"), MB_OK
);
471 STDMETHODIMP
CCallback::outSeqByte(LPSAFEARRAY
* outVal
)
473 // TODO: Add your implementation code here
478 STDMETHODIMP
CCallback::inSeqByte( LPSAFEARRAY listeners
)
484 STDMETHODIMP
CCallback::inSeqXEventListener( LPSAFEARRAY listeners
, LPSAFEARRAY events
)
490 hr
= SafeArrayGetUBound( listeners
, 1, &ubound
);
491 hr
= SafeArrayGetLBound( listeners
, 1, &lbound
);
492 count
= ubound
- lbound
+1;
494 // We assume thate the count of EventObjects in events is the same
495 for( long i
= 0; i
< count
; i
++)
497 CComVariant varListener
;
498 CComVariant varEvent
;
499 hr
= SafeArrayGetElement( listeners
, &i
, &varListener
);
500 hr
= SafeArrayGetElement( events
, &i
, &varEvent
);
501 if( varListener
.vt
== VT_DISPATCH
&& varEvent
.vt
== VT_DISPATCH
)
503 CComDispatchDriver
disp( varListener
.pdispVal
);
504 hr
= disp
.Invoke1(L
"disposing", &varEvent
);