merge the formfield patch from ooo-build
[ooovba.git] / extensions / test / ole / OleConverterVar1 / convTest.cxx
blobae69594c3cf6805903b58eedc71b09f11f2924ef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: convTest.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 #pragma warning (disable: 4917)
35 #include <windows.h>
36 #include <comdef.h>
37 #include <tchar.h>
38 #include <atlbase.h>
39 extern CComModule _Module;
40 #include<atlcom.h>
42 #include <stdio.h>
43 #include <com/sun/star/bridge/ModelDependent.hpp>
44 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46 #include <com/sun/star/uno/XComponentContext.hpp>
47 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
49 #include <oletest/XTestSequence.hpp>
50 #include <rtl/process.h>
51 #include <com/sun/star/uno/Reference.h>
52 #include <cppuhelper/servicefactory.hxx>
53 #include <cppuhelper/bootstrap.hxx>
54 #include <rtl/string.h>
57 CComModule _Module;
58 BEGIN_OBJECT_MAP(ObjectMap)
59 END_OBJECT_MAP()
61 #include "smartarray.h"
62 using namespace com::sun::star::bridge;
63 using namespace com::sun::star::bridge::ModelDependent;
64 using namespace com::sun::star::lang;
65 using namespace com::sun::star::uno;
66 using namespace oletest;
67 using namespace cppu;
68 using namespace rtl;
69 HRESULT doTest();
70 HRESULT InitializeParameter();
71 void printResultVariantArray( VARIANT & var);
72 void printVariant( VARIANT & var);
77 int __cdecl _tmain( int argc, _TCHAR * argv[] )
79 HRESULT hr;
80 if( FAILED( hr=CoInitialize(NULL)))
82 _tprintf(_T("CoInitialize failed \n"));
83 return -1;
87 _Module.Init( ObjectMap, GetModuleHandle( NULL));
89 if( FAILED(hr=doTest()))
91 _com_error err( hr);
92 const TCHAR * errMsg= err.ErrorMessage();
93 MessageBox( NULL, errMsg, "Test failed", MB_ICONERROR);
97 _Module.Term();
98 CoUninitialize();
99 return 0;
101 char _c[]={ 1,2,3,4,5};
102 short _short[]={0xffff, 1, 11 ,111, 1111 };
103 unsigned short _ushort[]={0xffff, 1, 11 ,111, 1111 };
104 long _long[]= { 0xffffffff, 11, 111 ,1111, 1111 };
105 unsigned long _ulong[]= { 0xffffffff, 11, 111 ,1111, 1111 };
106 float _float[]= { 12345.f, 1234.5f, 123.45f, 12.345f, 1.2345f};
107 double _double[]= {12345, 1234.5, 123.45, 12.345, 1.2345};
109 CComVariant _variant[]= {L"variant 1", L"variant2", L"variant3"};
110 wchar_t _wchar[]= {L'1', L'2', L'3', L'A', L' '};
111 BSTR _bstr[]={L"Ich", L"bin", L"ein", L"Hamburger", L"Jung"};
112 SmartArray<char> arByte( _c, 5, VT_I1);
113 SmartArray< short> arShort( _short, 5, VT_I2);
114 //SmartArray< unsigned short> arUShort( _ushort, 5, VT_UI2);
115 SmartArray< long> arLong( _long, 5, VT_I4);
116 //SmartArray< unsigned long> arULong( _ulong, 5, VT_UI4);
117 //SmartArray< float> arFloat( _float, 5, VT_R4 );
118 SmartArray< double> arDouble( _double, 5, VT_R8 );
119 //SmartArray< unsigned short> arWChar( _wchar, 5, VT_UI2 );
120 SmartArray< wchar_t* > arString( _bstr, 5, VT_BSTR);
121 SmartArray< VARIANT > arVariant( _variant, 3, VT_VARIANT);
124 HRESULT doTest()
126 HRESULT hr;
127 USES_CONVERSION;
128 CComPtr<IUnknown> spUnkMgr;
130 putenv("UNO_TYPES=types.rdb");
131 putenv("UNO_SERVICES=services.rdb");
132 Reference<XComponentContext> xContext = defaultBootstrap_InitialComponentContext();
134 Reference< XMultiComponentFactory > mgr = xContext->getServiceManager();//createRegistryServiceFactory( OUString(L"services.rdb"));
135 Reference< XInterface > xIntSupplier= mgr->createInstanceWithContext(
136 OUString(L"com.sun.star.bridge.OleBridgeSupplierVar1"), xContext);
137 Reference< XBridgeSupplier2 > xSuppl( xIntSupplier, UNO_QUERY);
138 Reference <XInterface> xOletest= mgr->createInstanceWithContext(
139 OUString(L"oletest.OleTest"), xContext);
140 Any any;
141 any <<= xOletest;
142 sal_uInt8 arId[16];
143 rtl_getGlobalProcessId( arId);
144 Any target= xSuppl->createBridge( any, Sequence<sal_Int8>( (sal_Int8*)arId, 16), UNO, OLE);
145 CComDispatchDriver oletest;
146 if (target.getValueTypeClass() == getCppuType((sal_uInt32*) 0).getTypeClass())
148 VARIANT* pVariant = *(VARIANT**)target.getValue();
150 oletest= pVariant->pdispVal;
152 VariantClear(pVariant);
153 CoTaskMemFree(pVariant);
156 CComVariant varRet;
157 CComVariant varParam1;
158 CComVariant varParam2;
159 CComVariant varParam3;
160 CComVariant varParam4;
162 long value= 100;
163 varParam1.vt= VT_I1 | VT_BYREF;
164 varParam1.plVal= &value;
166 // Testing the caching of DISPIDs and the process of aquiring member information
167 // on demand in IDispatch::Invoke
168 // Step through the corresponding IDispatch implementation of the ole bridge
169 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodByte"), &varParam1, &varRet);
170 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodByte"), &varParam1, &varRet);
171 // Name ok but different case
172 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"Testinout_methodByte"), &varParam1, &varRet);
173 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"Testinout_methodByte"), &varParam1, &varRet);
174 // not existing member
175 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"Testinout"), &varParam1, &varRet);
176 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"Testinout"), &varParam1, &varRet);
178 // Property
179 varParam1.vt= VT_ARRAY | VT_I1;
180 varParam1.parray= (SAFEARRAY*)arByte;
181 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varParam1);
182 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varParam1);
183 // Name ok but different case
184 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"attrByte"), &varParam1);
185 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"attrByte"), &varParam1);
186 // not existing member
187 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"attr"), &varParam1);
188 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"attr"), &varParam1);
190 // PropertyGet
191 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varRet);
193 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"attrByte"), &varRet);
194 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"attrByte"), &varRet);
195 //not existing member
196 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"attrBy"), &varRet);
197 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"attrBy"), &varRet);
199 DISPID dispid;
200 LPOLESTR method= L"methodByte";
201 hr = oletest.p->GetIDsOfNames(IID_NULL, &method, 1, LOCALE_USER_DEFAULT, &dispid);
204 CComVariant arg[1];
205 arg[0].vt= VT_ARRAY | VT_I1;
206 arg[0].parray= (SAFEARRAY*)arByte;
207 DISPPARAMS params={ arg,0,1,0};
209 hr = oletest.p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
210 DISPATCH_METHOD | DISPATCH_PROPERTYPUT, &params, &varRet, NULL, NULL);
212 hr = oletest.p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
213 DISPATCH_METHOD | DISPATCH_PROPERTYPUT, &params, &varRet, NULL, NULL);
215 // different case
216 LPOLESTR method2= L"MEthodByte";
217 hr = oletest.p->GetIDsOfNames(IID_NULL, &method2, 1, LOCALE_USER_DEFAULT, &dispid);
219 hr = oletest.p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
220 DISPATCH_METHOD | DISPATCH_PROPERTYPUT, &params, &varRet, NULL, NULL);
222 hr = oletest.p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
223 DISPATCH_METHOD | DISPATCH_PROPERTYPUT, &params, &varRet, NULL, NULL);
225 LPOLESTR attrib= L"AttrByte";
226 hr = oletest.p->GetIDsOfNames(IID_NULL, &attrib, 1, LOCALE_USER_DEFAULT, &dispid);
228 hr = oletest.p->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT,
229 DISPATCH_METHOD | DISPATCH_PROPERTYPUTREF, &params, &varRet, NULL, NULL);
231 hr = oletest.p->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT,
232 DISPATCH_METHOD | DISPATCH_PROPERTYGET, &params, &varRet, NULL, NULL);
236 CComVariant varByteArray;
237 varByteArray.vt= VT_ARRAY | VT_I1;
238 varByteArray.parray= (SAFEARRAY*)arByte;
239 CComVariant varShortArray;
240 varShortArray.vt= VT_ARRAY | VT_I2;
241 varShortArray.parray= (SAFEARRAY*)arShort;
242 CComVariant varLongArray;
243 varLongArray.vt= VT_ARRAY | VT_I4;
244 varLongArray.parray= (SAFEARRAY*)arLong;
245 CComVariant varDoubleArray;
246 varDoubleArray.vt= VT_ARRAY | VT_R8;
247 varDoubleArray.parray= (SAFEARRAY*)arDouble;
248 CComVariant varStringArray;
249 varStringArray.vt= VT_ARRAY | VT_BSTR;
250 varStringArray.parray= (SAFEARRAY*)arString;
251 CComVariant varArray;
252 varArray.vt= VT_ARRAY | VT_VARIANT;
253 varArray.parray= (SAFEARRAY*)arVariant;
255 FONTDESC fd={ sizeof( fd), L"ARIAL", 10, FW_NORMAL, 0, 0, 0, 0};
258 CComPtr< IUnknown > unk1;
259 CComPtr< IUnknown > unk2;
260 CComPtr< IUnknown > unk3;
262 IUnknown* _unknown[3];
263 hr= OleCreateFontIndirect( &fd, __uuidof( IUnknown), (void**)&unk1.p);
264 hr= OleCreateFontIndirect( &fd, __uuidof( IUnknown), (void**)&unk2.p);
265 hr= OleCreateFontIndirect( &fd, __uuidof( IUnknown), (void**)&unk3.p);
266 _unknown[0]= unk1;
267 _unknown[1]= unk2;
268 _unknown[2]= unk3;
269 SmartArray<IUnknown*> arUnknown( _unknown, 3, VT_UNKNOWN);
271 CComVariant varUnkArray;
272 varUnkArray.vt= VT_ARRAY | VT_UNKNOWN;
273 varUnkArray.parray= (SAFEARRAY*)arUnknown;
275 // preparing out parameter;
276 char byteOut;
277 CComVariant varOutByte; //###
278 varOutByte.vt= VT_BYREF | VT_UI1;
279 V_I1REF(&varOutByte)= &byteOut;
280 short shortOut;
281 CComVariant varOutShort; //###
282 varOutShort.vt= VT_BYREF | VT_I2;
283 V_I2REF( &varOutShort)= &shortOut;
284 long longOut;
285 CComVariant varOutLong; //###
286 varOutLong.vt= VT_BYREF | VT_I4;
287 V_I4REF( &varOutLong)= &longOut;
288 double doubleOut;
289 CComVariant varOutDouble; //###
290 varOutDouble.vt= VT_BYREF | VT_R8;
291 V_R8REF( &varOutDouble)= &doubleOut;
292 BSTR bstrOut= NULL;
293 CComVariant varOutString; //###
294 varOutString.vt= VT_BYREF | VT_BSTR;
295 V_BSTRREF(&varOutString)= &bstrOut;
296 CComVariant variantOut;
297 CComVariant varOutAny; //###
298 varOutAny.vt= VT_BYREF | VT_VARIANT;
299 V_VARIANTREF(&varOutAny)= &variantOut;
301 CComPtr<IDispatch> dispOut;
302 CComVariant varOutXInterface; //###
303 varOutXInterface.vt= VT_BYREF |VT_DISPATCH;
304 V_DISPATCHREF(&varOutXInterface)= &dispOut.p;
306 // In Parameter ( all of type Sequence ###########################################################
307 OutputDebugString( _T("In parameter of type Sequence ###########################################\n"
308 "The functions return the Sequence parameter \n\n"));
310 OutputDebugStringA("methodByte | Params: \n");
311 printVariant( varByteArray);
312 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodByte"), &varByteArray, &varRet);
313 OutputDebugStringA("methodByte | return value \n");
314 printVariant( varRet);
316 OutputDebugStringA("methodShort | Params: \n");
317 printVariant( varShortArray);
318 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodShort"), &varShortArray, &varRet);
319 OutputDebugStringA("methodShort | return value \n");
320 printVariant( varRet);
322 OutputDebugStringA("methodLong | Params: \n");
323 printVariant( varLongArray);
324 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodLong"), &varLongArray, &varRet);
325 OutputDebugStringA("methodLong | return value \n");
326 printVariant( varRet);
328 OutputDebugStringA("methodDouble | Params: \n");
329 printVariant( varDoubleArray);
330 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodDouble"), &varDoubleArray, &varRet);
331 OutputDebugStringA("methodDouble | return value \n");
332 printVariant( varRet);
334 OutputDebugStringA("methodString | Params: \n");
335 printVariant( varStringArray);
336 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodString"), &varStringArray, &varRet);
337 OutputDebugStringA("methodString | return value \n");
338 printVariant( varRet);
340 OutputDebugStringA("methodAny | Params: \n");
341 printVariant( varArray);
342 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodAny"), &varArray, &varRet);
343 OutputDebugStringA("methodAny | return value \n");
344 printVariant( varRet);
346 OutputDebugStringA("methodXInterface | Params: \n");
347 printVariant( varUnkArray);
348 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodXInterface"), &varUnkArray, &varRet);
349 OutputDebugStringA("methodAny | return value \n");
350 printVariant( varRet);
352 // Out Parameter ###########################################################################
353 OutputDebugString( _T("Out parameter ###########################################\n\n"));
355 OutputDebugString(_T("testout_methodByte \n"));
356 hr= oletest.InvokeN(static_cast<LPCOLESTR>(L"testout_methodByte"), &varOutByte, 1, &varRet);
357 OutputDebugString(_T("testout_methodByte | out value: \n"));
358 printVariant( varOutByte);
360 OutputDebugString(_T("testout_methodShort \n"));
361 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodShort"), &varOutShort, &varRet);
362 OutputDebugString(_T("testout_methodShort | out value: \n"));
363 printVariant( varOutShort);
365 OutputDebugString(_T("testout_methodLong \n"));
366 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodLong"), &varOutLong, &varRet);
367 OutputDebugString(_T("testout_methodLong | out value: \n"));
368 printVariant( varOutLong);
370 OutputDebugString(_T("testout_methodDouble \n"));
371 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodDouble"), &varOutDouble, &varRet);
372 OutputDebugString(_T("testout_methodDouble | out value: \n"));
373 printVariant( varOutDouble);
375 OutputDebugString(_T("testout_methodString \n"));
376 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodString"), &varOutString, &varRet);
377 OutputDebugString(_T("testout_methodString | out value: \n"));
378 printVariant( varOutString);
380 OutputDebugString(_T("testout_methodAny \n"));
381 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodAny"), &varOutAny, &varRet);
382 OutputDebugString(_T("methodAny | out value: \n"));
383 printVariant( varOutAny);
385 OutputDebugString(_T("testout_methodXInterface \n"));
386 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodXInterface"), &varOutXInterface, &varRet);
387 OutputDebugString(_T("methodAny | out value: \n"));
388 printVariant( varOutXInterface);
389 CComDispatchDriver outDisp( *varOutXInterface.ppdispVal);
390 CComVariant varAttr3;
391 outDisp.GetPropertyByName(L"AttrAny2", &varAttr3);
392 ATLTRACE("property OleTest.AttrAny2: %s", W2T(varAttr3.bstrVal));
394 OutputDebugString(_T("testout_methodMulParams1 ( 2 out Parameter) \n"));
395 long longOut2=0;
396 CComVariant _params[2];
397 longOut=0;
398 _params[0]= varOutLong;
399 _params[1].vt= VT_BYREF | VT_I4;
400 V_I4REF(& _params[1])= &longOut2;
401 hr= oletest.InvokeN( static_cast<LPCOLESTR>(L"testout_methodMulParams1"), (VARIANT*)&_params, 2);
402 OutputDebugString(_T("testout_methodMulParams1 | out values: \n"));
403 printVariant( _params[1]);
404 printVariant( _params[0]);
406 OutputDebugString(_T("testout_methodMulParams2 ( 3 out Parameter) \n"));
407 CComVariant _params2[3];
408 _params2[2]= varOutLong;
409 _params2[1].vt= VT_BYREF | VT_I4;
410 V_I4REF(& _params2[1])= &longOut2;
411 _params2[0]= varOutString;
412 hr= oletest.InvokeN( static_cast<LPCOLESTR>( L"testout_methodMulParams2"), (VARIANT*)&_params2, 3);
413 OutputDebugString(_T("testout_methodMulParams2 | out values: \n"));
414 printVariant( _params2[2]);
415 printVariant( _params2[1]);
416 printVariant( _params2[0]);
418 OutputDebugString(_T("testout_methodMulParams3 ( 1 in and 1 out Parameter) \n"));
419 CComVariant _params3[2];
420 _params3[1]= CComBSTR(L" In string");
421 _params3[0]= varOutString;
422 hr= oletest.InvokeN( static_cast<LPCOLESTR>( L"testout_methodMulParams3"), (VARIANT*)&_params3, 2);
423 OutputDebugString(_T("testout_methodMulParams3 | out values: \n"));
424 printVariant( _params3[1]);
425 printVariant( _params3[0]);
427 //In Out Parameter ###########################################################################
428 OutputDebugString( _T("In Out parameter ###########################################\n\n"));
430 *V_I1REF(&varOutByte)= 5;
431 ATLTRACE(_T("testinout_methodByte | in value: %d \n"), *V_I1REF(&varOutByte));
432 hr= oletest.InvokeN(static_cast<LPCOLESTR>(L"testinout_methodByte"), &varOutByte, 1, &varRet);
433 OutputDebugString(_T("testinout_methodByte | out value: \n"));
434 printVariant( varOutByte);
436 OutputDebugString(_T("testinout_methodShort | in value= 1000 \n"));
437 *V_UI2REF(&varOutShort)= 1000;
438 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodShort"), &varOutShort, &varRet);
439 OutputDebugString(_T("testinout_methodShort | out value: \n"));
440 printVariant( varOutShort);
442 OutputDebugString(_T("testinout_methodLong | in value= 10000 \n"));
443 *V_UI4REF(&varOutLong)= 10000;
444 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodLong"), &varOutLong, &varRet);
445 OutputDebugString(_T("testinout_methodLong | out value: \n"));
446 printVariant( varOutLong);
448 *V_R8REF(&varOutDouble)= 3.14;
449 ATLTRACE(_T("testinou_methodDouble in value: %f \n"),*V_R8REF(&varOutDouble));
450 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodDouble"), &varOutDouble, &varRet);
451 OutputDebugString(_T("testinout_methodDouble | out value: \n"));
452 printVariant( varOutDouble);
454 SysFreeString( *V_BSTRREF(&varOutString));
455 *V_BSTRREF(&varOutString)= SysAllocString( L"this is a in string");
456 ATLTRACE(_T("testinout_methodString | value: %s \n"), W2T(*V_BSTRREF(&varOutString)));
457 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodString"), &varOutString, &varRet);
458 OutputDebugString(_T("testinout_methodString | out value: \n"));
459 printVariant( varOutString);
461 CComVariant var1(CComBSTR(L" this is a string in a VARIANT"));
462 CComVariant outVar1;
463 outVar1.vt= VT_BYREF | VT_VARIANT;
464 outVar1.pvarVal= &var1;
465 ATLTRACE(_T("testinout_methodAny | parameter: %s\n"), W2T(var1.bstrVal));
466 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodAny"), &varOutAny, &varRet);
467 OutputDebugString(_T("testinout_methodAny | out value: \n"));
468 printVariant( varOutAny);
470 CComPtr< IUnknown > objectIn = unk1;
471 CComVariant varOutIFace;
472 varOutIFace.vt= VT_BYREF | VT_UNKNOWN;
473 varOutIFace.ppunkVal= &objectIn.p;
474 (*varOutIFace.ppunkVal)->AddRef();
475 OutputDebugString(_T("testinout_methodXInterface | in value: \n"));
476 printVariant(varOutIFace);
477 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodXInterface"), &varOutIFace, &varRet);
478 OutputDebugString(_T("testinout_methodXInterface | out value: \n"));
479 printVariant( varOutIFace);
481 // Properties ######################################################################
482 OutputDebugString( _T(" Properties ###########################################\n\n"));
484 OutputDebugString(_T("set property \"AttrByte\" | value"));
485 //CComVariant propArByte;
486 //propArByte.vt= VT_ARRAY | VT_I1;
487 varParam1.parray= (SAFEARRAY*)arByte;
488 printVariant( varParam1);
489 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varParam1);
490 OutputDebugString(_T("get property \"AttrByte\" | value:"));
491 varRet.Clear();
492 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varRet);
493 printVariant( varRet);
496 return S_OK;
502 void printVariant( VARIANT & _var)
504 HRESULT hr;
505 USES_CONVERSION;
506 CComVariant var;
507 hr= VariantCopyInd( &var, &_var);
508 if( var.vt & VT_ARRAY)
510 VARTYPE type= var.vt ^ VT_ARRAY;
511 SAFEARRAY * sarray= var.parray;
512 long lbound;
513 long ubound;
514 hr= SafeArrayGetLBound( sarray, 1, &lbound);
515 hr= SafeArrayGetUBound( sarray, 1, &ubound);
516 long count= ubound - lbound + 1;
517 char charValue;
518 BYTE byteValue;
519 short shortValue;
520 long longValue;
521 double doubleValue;
522 IUnknown* unkValue;
523 BSTR bstrValue;
524 OutputDebugString( _T("# Array \n"));
525 for( long i= 0; i < count; i++)
527 // CComVariant variantValue;
528 TCHAR *buf[256];
529 wsprintf( (TCHAR*)buf, _T("%d : "), i);
530 OutputDebugString( (TCHAR*)buf);
531 VARIANT varTemp;
532 VariantInit( &varTemp);
533 VARIANT variantValue;
534 VariantInit( &variantValue);
535 switch( type)
537 case VT_UI1:
538 hr= SafeArrayGetElement( sarray, &i, &byteValue);
539 varTemp.vt= VT_UI1;
540 V_UI1( &varTemp)= byteValue;
541 printVariant( varTemp);
542 break;
543 case VT_I1:
544 hr= SafeArrayGetElement( sarray, &i, &charValue);
545 varTemp.vt= VT_I1;
546 V_I1( &varTemp)= charValue;
547 printVariant( varTemp);
548 break;
549 case VT_I2:
550 hr= SafeArrayGetElement( sarray, &i, &shortValue);
551 varTemp.vt= VT_I2;
552 V_I2( &varTemp)= shortValue;
553 printVariant( varTemp);
554 break;
556 case VT_UI2:
557 case VT_I4:
558 hr= SafeArrayGetElement( sarray, &i, &longValue);
559 varTemp.vt= VT_I4;
560 V_I4( &varTemp)= longValue;
561 printVariant( varTemp);
562 break;
563 case VT_R8:
564 hr= SafeArrayGetElement( sarray, &i, &doubleValue);
565 varTemp.vt= VT_R8;
566 V_R8( &varTemp)= doubleValue;
567 printVariant( varTemp);
568 break;
569 case VT_BSTR:
570 hr= SafeArrayGetElement( sarray, &i, &bstrValue);
571 varTemp.vt= VT_BSTR;
572 varTemp.bstrVal= bstrValue;
573 printVariant( varTemp);
574 break;
575 case VT_VARIANT:
576 hr= SafeArrayGetElement( sarray, &i, &varTemp);
577 printVariant( varTemp);
578 break;
580 case VT_UNKNOWN:
581 hr= SafeArrayGetElement( sarray, &i, &unkValue);
582 varTemp.vt= VT_UNKNOWN;
583 varTemp.punkVal= unkValue;
584 printVariant( varTemp);
585 break;
588 VariantClear( &varTemp);
589 VariantClear( &variantValue);
593 else
595 TCHAR buf[256];
596 switch (var.vt)
598 case VT_I1: wsprintf( (TCHAR*)buf, _T(" VT_I1: %d \n"), V_I1( &var) );
599 break;
600 case VT_UI1: wsprintf( (TCHAR*)buf, _T(" VT_UI1: %d \n"), V_I1( &var) );
601 break;
603 case VT_I2: wsprintf( (TCHAR*)buf, _T(" VT_I2: %d \n"), V_I2( &var) );
604 break;
605 case VT_I4: wsprintf( (TCHAR*)buf, _T(" VT_I4: %d \n"), V_I4( &var) );
606 break;
607 case VT_R8:
610 // int decimal, sign;
611 // char *buffer;
612 // int precision = 14;
613 // double source = 3.1415926535;
615 // buffer = _ecvt( V_R8(&var), precision, &decimal, &sign );
616 sprintf( (TCHAR*)buf, _T(" VT_R8: %f \n"),V_R8( &var) );
617 break;
619 case VT_UNKNOWN:
620 // The object implement IFont
622 CComDispatchDriver disp( var.punkVal);
623 CComVariant ret;
624 hr= disp.GetPropertyByName( static_cast<LPCOLESTR>(L"Name"), &ret);
625 wsprintf( (TCHAR*)buf, _T(" VT_UNKNOWN: property \"Name\": %s \n"), W2T(ret.bstrVal));
626 break;
628 case VT_DISPATCH:
629 // The object implement IFont
631 CComDispatchDriver disp( var.punkVal);
632 CComVariant ret;
633 if( SUCCEEDED( hr= disp.GetPropertyByName( static_cast<LPCOLESTR>(L"Name"), &ret)))
634 wsprintf( (TCHAR*)buf, _T(" VT_DISPATCH: property \"Name\": %s \n"), W2T(ret.bstrVal));
635 else
636 wsprintf( (TCHAR*)buf, _T(" VT_DISPATCH \n"));
638 break;
642 case VT_BSTR:
644 TCHAR* str= W2T( var.bstrVal);
645 wsprintf( (TCHAR*)buf, _T(" VT_BSTR: %s \n"), str);
647 break;
648 default:
649 wsprintf( (TCHAR*)buf, _T("\n"));
653 OutputDebugString( (TCHAR*) buf);
656 return;