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