1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 // Callback.cpp : Implementation of CCallback
21 #include "XCallback_Impl.h"
28 STDMETHODIMP
CCallback::func1()
30 MessageBox( NULL
, _T("Callback::func1 called"),_T(""), MB_OK
);
34 STDMETHODIMP
CCallback::returnInterface(IDispatch
**ppdisp
)
38 CComPtr
<IDispatch
> spDisp
;
39 spDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
45 STDMETHODIMP
CCallback::outInterface(IDispatch
**ppdisp
)
50 CComPtr
<IDispatch
> spDisp
;
51 spDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
55 // MessageBox( NULL, _T("CCallback::outInterface"), _T(""), MB_OK);
59 STDMETHODIMP
CCallback::outValuesMixed(long val
, long *pval
, BSTR string
)
64 sprintf( buff
, "param1: %d, param2 out: %d, param3: %S", val
, *pval
, string
);
65 MessageBox( NULL
, A2T(buff
), A2T("XCallback_Impl.Callback"), MB_OK
);
70 STDMETHODIMP
CCallback::outValuesAll(
71 /* [out] */ IDispatch __RPC_FAR
*__RPC_FAR
*ppdisp
,
72 /* [out] */ IDispatch __RPC_FAR
*__RPC_FAR
*ppSimpleStruct
,
73 /* [out] */ long __RPC_FAR
*aSimpleEnum
,
74 /* [out] */ SAFEARRAY __RPC_FAR
* __RPC_FAR
*outSeq
,
75 /* [out] */ VARIANT __RPC_FAR
*varAny
,
76 /* [out] */ VARIANT_BOOL __RPC_FAR
*aBool
,
77 /* [out] */ short __RPC_FAR
*aChar
,
78 /* [out] */ BSTR __RPC_FAR
*aString
,
79 /* [out] */ float __RPC_FAR
*aFloat
,
80 /* [out] */ double __RPC_FAR
*aDouble
,
81 /* [out] */ unsigned char __RPC_FAR
*aByte
,
82 /* [out] */ short __RPC_FAR
*aShort
,
83 /* [out] */ long __RPC_FAR
*aLong
)
86 // if( ! ppdisp || ! ppSimpleStruct || ! aSimpleEnum ||
87 // ! outSeq || !varAny ||! aBool || ! aChar ||
88 // ! aString || ! aFloat || ! aDouble || ! aByte ||
89 // ! aShort || ! aLong || ! aUShort || ! aULong)
93 hr
= outInterface( ppdisp
);
94 hr
= outStruct( ppSimpleStruct
);
95 hr
= outEnum( aSimpleEnum
);
96 hr
= outSeqAny( outSeq
);
100 hr
= outString( aString
);
101 hr
= outFloat( aFloat
);
102 hr
= outDouble( aDouble
);
104 hr
= outShort( aShort
);
109 STDMETHODIMP
CCallback::outStruct(IDispatch
**outStruct
)
115 // MessageBox( NULL, _T("CCallback::outStruct"), _T(""), MB_OK);
117 CComPtr
<IDispatch
> _dispMgr
;
118 if( SUCCEEDED(hr
= _dispMgr
.CoCreateInstance(L
"com.sun.star.ServiceManager")))
120 CComDispatchDriver
manager( _dispMgr
);
121 CComVariant
param1(L
"com.sun.star.reflection.CoreReflection");
123 hr
= manager
.Invoke1( L
"createInstance", ¶m1
, &varRet
);
125 CComDispatchDriver
reflection( varRet
.pdispVal
);
126 param1
= L
"oletest.SimpleStruct";
128 hr
= reflection
.Invoke1( L
"forName", ¶m1
, &varRet
);
130 CComDispatchDriver
classSimpleStruct( varRet
.pdispVal
);
132 CComPtr
<IDispatch
> dispStruct
;
133 param1
.vt
= VT_DISPATCH
| VT_BYREF
;
134 param1
.ppdispVal
= &dispStruct
;
135 if( SUCCEEDED( hr
= classSimpleStruct
.Invoke1(L
"createObject", ¶m1
)))
138 CComDispatchDriver
simpleStruct( dispStruct
);
139 param1
=L
" this is a property string";
140 hr
= simpleStruct
.PutPropertyByName(L
"message", ¶m1
);
141 *outStruct
= dispStruct
;
142 (*outStruct
)->AddRef();
149 STDMETHODIMP
CCallback::outEnum(long *outEnum
)
157 STDMETHODIMP
CCallback::outSeqAny(LPSAFEARRAY
* outSeq
)
160 SAFEARRAY
* pArr
= SafeArrayCreateVector( VT_VARIANT
, 0, 3);
162 var
[0]=L
" variant 0";
163 var
[1]=L
" variant 1";
165 for( long i
=0; i
<3; i
++)
167 SafeArrayPutElement( pArr
, &i
, (void*)&var
[i
]);
174 // ATLASSERT //VT_EMPTY
177 STDMETHODIMP
CCallback::outAny(VARIANT
*outAny
)
182 outAny
->bstrVal
= SysAllocString( L
"This is a string in a VARIANT");
187 STDMETHODIMP
CCallback::outBool(VARIANT_BOOL
*outBool
)
191 *outBool
= VARIANT_TRUE
;
195 STDMETHODIMP
CCallback::outChar(short *outChar
)
199 *outChar
= (short)L
'A';
203 STDMETHODIMP
CCallback::outString(BSTR
*outString
)
207 *outString
= SysAllocString(L
"This is a BSTR");
211 STDMETHODIMP
CCallback::outFloat(float *outFloat
)
219 STDMETHODIMP
CCallback::outDouble(double *outDouble
)
230 STDMETHODIMP
CCallback::outShort(short *outShort
)
238 STDMETHODIMP
CCallback::outLong(long *outLong
)
242 *outLong
= 0xffffffff;
248 STDMETHODIMP
CCallback::outByte(unsigned char* outByte
)
256 STDMETHODIMP
CCallback::inoutInterface(IDispatch
**ppdisp
)
260 CComDispatchDriver
disp( *ppdisp
);
261 CComVariant
param1(L
"");
262 disp
.Invoke1(L
"func", ¶m1
);
264 (*ppdisp
)->Release();
266 CComPtr
<IDispatch
> outDisp
;
267 outDisp
.CoCreateInstance( L
"XCallback_Impl.Simple");
274 STDMETHODIMP
CCallback::inoutStruct(IDispatch
**inoutVal
)
281 CComDispatchDriver
disp( *inoutVal
);
283 hr
= disp
.GetPropertyByName(L
"message", &var
);
284 MessageBox( NULL
, W2T(var
.bstrVal
), _T("XCallback_Impl.Callback"), MB_OK
);
286 (*inoutVal
)->Release();
288 CComDispatchDriver dispStruct
;
289 hr
= outStruct( &dispStruct
.p
);
291 var
= L
"This struct was created in XCallback_Imp.Callback";
292 hr
= dispStruct
.PutPropertyByName(L
"message", &var
);
294 *inoutVal
= dispStruct
;
295 (*inoutVal
)->AddRef();
299 STDMETHODIMP
CCallback::inoutEnum(long *inoutVal
)
303 *inoutVal
= *inoutVal
+1;
308 STDMETHODIMP
CCallback::inoutSeqAny(LPSAFEARRAY
*pArray
)
315 hr
= SafeArrayGetLBound( *pArray
, 1, &lbound
);
316 hr
= SafeArrayGetUBound( *pArray
, 1, &ubound
);
317 long count
= ubound
- lbound
+ 1;
319 // the Array is supposet to contain variants
321 for( long i
=0; i
<count
; i
++)
324 hr
= SafeArrayGetElement( *pArray
, &i
, (void*)&var
);
327 SafeArrayDestroy( *pArray
);
333 STDMETHODIMP
CCallback::inoutAny(VARIANT
*inoutVal
)
338 if( inoutVal
->vt
= VT_BSTR
)
339 MessageBox( NULL
, W2T( inoutVal
->bstrVal
), _T("XCallback_Impl.Callback"), MB_OK
);
341 VariantClear( inoutVal
);
342 inoutVal
->vt
= VT_BSTR
;
343 inoutVal
->bstrVal
=SysAllocString( L
" [string] XCallback_Impl.Callback inoutAny");
347 STDMETHODIMP
CCallback::inoutBool(VARIANT_BOOL
*inoutVal
)
352 *inoutVal
= *inoutVal
== VARIANT_TRUE
? VARIANT_FALSE
: VARIANT_TRUE
;
356 STDMETHODIMP
CCallback::inoutChar(short *inoutVal
)
362 sprintf( buff
, "character value: %C", *inoutVal
);
363 MessageBox( NULL
, A2T(buff
), _T("XCallback_Impl.Callback"), MB_OK
);
368 STDMETHODIMP
CCallback::inoutString(BSTR
*inoutVal
)
373 MessageBox( NULL
, W2T(*inoutVal
), _T("XCallback_Impl.Callback"), MB_OK
);
374 SysFreeString(*inoutVal
);
375 *inoutVal
= SysAllocString(L
"a string from XCallback_Impl.Callback");
380 STDMETHODIMP
CCallback::inoutFloat(float *inoutVal
)
384 *inoutVal
= *inoutVal
+1;
388 STDMETHODIMP
CCallback::inoutDouble(double *inoutVal
)
392 *inoutVal
= *inoutVal
+1;
396 STDMETHODIMP
CCallback::inoutByte(unsigned char *inoutVal
)
404 STDMETHODIMP
CCallback::inoutShort(short *inoutVal
)
412 STDMETHODIMP
CCallback::inoutLong(long* inoutVal
)
416 *inoutVal
= 0xffffffff;
420 STDMETHODIMP
CCallback::inoutValuesAll(
421 /* [out][in] */ IDispatch __RPC_FAR
*__RPC_FAR
*aXSimple
,
422 /* [out][in] */ IDispatch __RPC_FAR
*__RPC_FAR
*aStruct
,
423 /* [out][in] */ long __RPC_FAR
*aEnum
,
424 /* [out][in] */ SAFEARRAY __RPC_FAR
* __RPC_FAR
*aSeq
,
425 /* [out][in] */ VARIANT __RPC_FAR
*aAny
,
426 /* [out][in] */ VARIANT_BOOL __RPC_FAR
*aBool
,
427 /* [out][in] */ short __RPC_FAR
*aChar
,
428 /* [out][in] */ BSTR __RPC_FAR
*aString
,
429 /* [out][in] */ float __RPC_FAR
*aFloat
,
430 /* [out][in] */ double __RPC_FAR
*aDouble
,
431 /* [out][in] */ unsigned char __RPC_FAR
*aByte
,
432 /* [out][in] */ short __RPC_FAR
*aShort
,
433 /* [out][in] */ long __RPC_FAR
*aLong
)
435 inoutInterface( aXSimple
);
436 inoutStruct( aStruct
);
442 inoutString( aString
);
444 inoutDouble( aDouble
);
453 STDMETHODIMP
CCallback::inValues(short aChar
, long aLong
, BSTR aString
)
456 wchar_t _char
= (wchar_t) aChar
;
458 sprintf( buff
, "Parameters: char= %C, long= %d, string= %s", _char
, aLong
, W2A(aString
));
459 MessageBox( NULL
, A2T(buff
), _T("XCallback_Impl.Callback"), MB_OK
);
463 STDMETHODIMP
CCallback::outSeqByte(LPSAFEARRAY
* outVal
)
465 // TODO: Add your implementation code here
470 STDMETHODIMP
CCallback::inSeqByte( LPSAFEARRAY listeners
)
476 STDMETHODIMP
CCallback::inSeqXEventListener( LPSAFEARRAY listeners
, LPSAFEARRAY events
)
482 hr
= SafeArrayGetUBound( listeners
, 1, &ubound
);
483 hr
= SafeArrayGetLBound( listeners
, 1, &lbound
);
484 count
= ubound
- lbound
+1;
486 // We assume that the count of EventObjects in events is the same
487 for( long i
= 0; i
< count
; i
++)
489 CComVariant varListener
;
490 CComVariant varEvent
;
491 hr
= SafeArrayGetElement( listeners
, &i
, &varListener
);
492 hr
= SafeArrayGetElement( events
, &i
, &varEvent
);
493 if( varListener
.vt
== VT_DISPATCH
&& varEvent
.vt
== VT_DISPATCH
)
495 CComDispatchDriver
disp( varListener
.pdispVal
);
496 hr
= disp
.Invoke1(L
"disposing", &varEvent
);
505 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */