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