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 // Test.cpp : Defines the entry point for the console application. 28*cdf0e10cSrcweir // 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "stdafx.h" 31*cdf0e10cSrcweir #include "../XCallback_Impl/XCallback_Impl.h" 32*cdf0e10cSrcweir #include "../XCallback_Impl/XCallback_Impl_i.c" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir CComModule _Module; 35*cdf0e10cSrcweir BEGIN_OBJECT_MAP(ObjectMap) 36*cdf0e10cSrcweir END_OBJECT_MAP() 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir HRESULT doTest(); 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir int main(int argc, char* argv[]) 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir HRESULT hr; 43*cdf0e10cSrcweir if( FAILED( hr=CoInitialize(NULL))) 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir _tprintf(_T("CoInitialize failed \n")); 46*cdf0e10cSrcweir return -1; 47*cdf0e10cSrcweir } 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir _Module.Init( ObjectMap, GetModuleHandle( NULL)); 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir if( FAILED(hr=doTest())) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir _com_error err( hr); 55*cdf0e10cSrcweir const TCHAR * errMsg= err.ErrorMessage(); 56*cdf0e10cSrcweir MessageBox( NULL, errMsg, "Test failed", MB_ICONERROR); 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir _Module.Term(); 61*cdf0e10cSrcweir CoUninitialize(); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir return 0; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir HRESULT doTest() 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir HRESULT hr= S_OK; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir CComPtr<IUnknown> spUnk; 73*cdf0e10cSrcweir hr= spUnk.CoCreateInstance(L"com.sun.star.ServiceManager"); 74*cdf0e10cSrcweir if( FAILED( hr)) 75*cdf0e10cSrcweir return hr; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir CComDispatchDriver manager( spUnk); 78*cdf0e10cSrcweir CComVariant param( L"oletest.OleTest"); 79*cdf0e10cSrcweir CComVariant retVal; 80*cdf0e10cSrcweir hr= manager.Invoke1((LPCOLESTR)L"createInstance", ¶m, &retVal ); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir CComDispatchDriver oletest( retVal.punkVal); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir spUnk.Release(); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir hr= spUnk.CoCreateInstance(L"XCallback_Impl.Callback"); 87*cdf0e10cSrcweir if( FAILED( hr)) 88*cdf0e10cSrcweir return hr; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir CComQIPtr<IDispatch> paramDisp(spUnk); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir //###################################################################### 94*cdf0e10cSrcweir // out parameters 95*cdf0e10cSrcweir //###################################################################### 96*cdf0e10cSrcweir CComVariant param1( paramDisp); 97*cdf0e10cSrcweir CComVariant param2(1); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // oletest calls XCallback::func1 100*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 101*cdf0e10cSrcweir // XCallback::returnInterface 102*cdf0e10cSrcweir param2= 2; 103*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 104*cdf0e10cSrcweir // XCallback::outInterface 105*cdf0e10cSrcweir param2= 3; 106*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 107*cdf0e10cSrcweir // XCallback::outStruct 108*cdf0e10cSrcweir param2= 4; 109*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 110*cdf0e10cSrcweir // XCallback::outEnum 111*cdf0e10cSrcweir param2= 5; 112*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 113*cdf0e10cSrcweir // XCallback::outSeqAny 114*cdf0e10cSrcweir param2= 6; 115*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 116*cdf0e10cSrcweir // XCallback::outAny 117*cdf0e10cSrcweir param2= 7; 118*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 119*cdf0e10cSrcweir // XCallback::outBool 120*cdf0e10cSrcweir param2= 8; 121*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 122*cdf0e10cSrcweir // XCallback::outChar 123*cdf0e10cSrcweir param2= 9; 124*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 125*cdf0e10cSrcweir // XCallback::outString 126*cdf0e10cSrcweir param2= 10; 127*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 128*cdf0e10cSrcweir // XCallback::outFloat 129*cdf0e10cSrcweir param2= 11; 130*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 131*cdf0e10cSrcweir // XCallback::outDouble 132*cdf0e10cSrcweir param2= 12; 133*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 134*cdf0e10cSrcweir // XCallback::outByte 135*cdf0e10cSrcweir param2= 13; 136*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 137*cdf0e10cSrcweir // XCallback::outShort 138*cdf0e10cSrcweir param2= 14; 139*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 140*cdf0e10cSrcweir // XCallback::outLong 141*cdf0e10cSrcweir param2= 15; 142*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 143*cdf0e10cSrcweir // XCallback::outValuesMixed 144*cdf0e10cSrcweir param2= 30; 145*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 146*cdf0e10cSrcweir // XCallback::outValuesAll 147*cdf0e10cSrcweir param2= 31; 148*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir // XCallback::outSeqByte 151*cdf0e10cSrcweir // Does not work currently because Sequences are always converted to 152*cdf0e10cSrcweir // SAFEARRAY( VARIANT) 153*cdf0e10cSrcweir // param2= 32; 154*cdf0e10cSrcweir // hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir //###################################################################### 157*cdf0e10cSrcweir // in / out parameters 158*cdf0e10cSrcweir //###################################################################### 159*cdf0e10cSrcweir // XCallback::inoutInterface 160*cdf0e10cSrcweir param2= 100; 161*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 162*cdf0e10cSrcweir // XCallback::inoutStruct 163*cdf0e10cSrcweir param2= 101; 164*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 165*cdf0e10cSrcweir // XCallback::inoutEnum 166*cdf0e10cSrcweir param2= 102; 167*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 168*cdf0e10cSrcweir // XCallback::inoutSeqAny 169*cdf0e10cSrcweir param2= 103; 170*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 171*cdf0e10cSrcweir // XCallback::inoutAny 172*cdf0e10cSrcweir param2= 104; 173*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 174*cdf0e10cSrcweir // XCallback::inoutBool 175*cdf0e10cSrcweir param2= 105; 176*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 177*cdf0e10cSrcweir // XCallback::inoutChar 178*cdf0e10cSrcweir param2= 106; 179*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 180*cdf0e10cSrcweir // XCallback::inoutString 181*cdf0e10cSrcweir param2= 107; 182*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 183*cdf0e10cSrcweir // XCallback::inoutFloat 184*cdf0e10cSrcweir param2= 108; 185*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 186*cdf0e10cSrcweir // XCallback::inoutDouble 187*cdf0e10cSrcweir param2= 109; 188*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 189*cdf0e10cSrcweir // XCallback::inoutByte 190*cdf0e10cSrcweir param2= 110; 191*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 192*cdf0e10cSrcweir // XCallback::inoutShort 193*cdf0e10cSrcweir param2= 111; 194*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 195*cdf0e10cSrcweir // XCallback::inoutLong 196*cdf0e10cSrcweir param2= 112; 197*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 198*cdf0e10cSrcweir // XCallback::inoutValuesAll 199*cdf0e10cSrcweir param2=120; 200*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 201*cdf0e10cSrcweir //###################################################################### 202*cdf0e10cSrcweir // in parameters 203*cdf0e10cSrcweir //###################################################################### 204*cdf0e10cSrcweir // XCallback::inValues 205*cdf0e10cSrcweir param2= 200; 206*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 207*cdf0e10cSrcweir // XCallback::inSeqByte 208*cdf0e10cSrcweir // SAFEARRAY( VARIANT) 209*cdf0e10cSrcweir param2= 201; 210*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 211*cdf0e10cSrcweir //XCallback::inSeqXEventListener 212*cdf0e10cSrcweir param2= 202; 213*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 214*cdf0e10cSrcweir //###################################################################### 215*cdf0e10cSrcweir // The UNO test component OleTest calls on XCallback_Impl.Callback directly 216*cdf0e10cSrcweir // that is the COM object has not been past a parameter but rather OleTest 217*cdf0e10cSrcweir // creates the COM object itself 218*cdf0e10cSrcweir //###################################################################### 219*cdf0e10cSrcweir // XCallback::outValuesAll 220*cdf0e10cSrcweir // does not work currently 221*cdf0e10cSrcweir param2= 300; 222*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 223*cdf0e10cSrcweir // XCallback::inoutValuesAll 224*cdf0e10cSrcweir param2= 301; 225*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 226*cdf0e10cSrcweir // XCallback::inoutValues 227*cdf0e10cSrcweir param2= 302; 228*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir // XCallback::inValues 231*cdf0e10cSrcweir param2= 303; 232*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface", ¶m1, ¶m2); 233*cdf0e10cSrcweir //###################################################################### 234*cdf0e10cSrcweir // Test a COM object which implements several interfaces. 235*cdf0e10cSrcweir //###################################################################### 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir CComQIPtr<IDispatch> dispSimple; 238*cdf0e10cSrcweir hr= dispSimple.CoCreateInstance(L"XCallback_Impl.Simple"); 239*cdf0e10cSrcweir CComVariant varSimple( dispSimple); 240*cdf0e10cSrcweir param2= 0; 241*cdf0e10cSrcweir hr= oletest.Invoke2(L"testInterface2", &varSimple, ¶m2); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir return hr; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir // VARIANT CComVariant VT_UNKNOWN VT_DISPATCH V_UI1 CComDispatchDriver WINAPI 246*cdf0e10cSrcweir 247