bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / test / ole / OleConverterVar1 / convTest.cxx
blobc0acc3152abf6097a5b98768aba3e5acd6152d40
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #pragma warning (disable: 4917)
22 #if !defined WIN32_LEAN_AND_MEAN
23 # define WIN32_LEAN_AND_MEAN
24 #endif
25 #include <windows.h>
26 #include <comdef.h>
27 #include <atlbase.h>
28 extern CComModule _Module;
29 #include <atlcom.h>
31 #include <stdio.h>
32 #include <com/sun/star/bridge/ModelDependent.hpp>
33 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
38 #include <oletest/XTestSequence.hpp>
39 #include <rtl/process.h>
40 #include <com/sun/star/uno/Reference.h>
41 #include <cppuhelper/servicefactory.hxx>
42 #include <cppuhelper/bootstrap.hxx>
43 #include <rtl/string.h>
46 CComModule _Module;
47 BEGIN_OBJECT_MAP(ObjectMap)
48 END_OBJECT_MAP()
50 #include "smartarray.h"
51 using namespace com::sun::star::bridge;
52 using namespace com::sun::star::bridge::ModelDependent;
53 using namespace com::sun::star::lang;
54 using namespace com::sun::star::uno;
55 using namespace oletest;
56 using namespace cppu;
59 HRESULT doTest();
60 HRESULT InitializeParameter();
61 void printResultVariantArray( VARIANT & var);
62 void printVariant( VARIANT & var);
65 int SAL_CALL main( int argc, char* argv[] )
67 HRESULT hr;
68 if( FAILED( hr=CoInitialize(NULL)))
70 printf("CoInitialize failed \n");
71 return -1;
75 _Module.Init( ObjectMap, GetModuleHandleA( NULL));
77 if( FAILED(hr=doTest()))
79 _com_error err( hr);
80 const CHAR * errMsg= err.ErrorMessage();
81 MessageBoxA( NULL, errMsg, "Test failed", MB_ICONERROR);
85 _Module.Term();
86 CoUninitialize();
87 return 0;
89 char _c[]={ 1,2,3,4,5};
90 short _short[]={0xffff, 1, 11 ,111, 1111 };
91 unsigned short _ushort[]={0xffff, 1, 11 ,111, 1111 };
92 long _long[]= { 0xffffffff, 11, 111 ,1111, 1111 };
93 unsigned long _ulong[]= { 0xffffffff, 11, 111 ,1111, 1111 };
94 float _float[]= { 12345.f, 1234.5f, 123.45f, 12.345f, 1.2345f};
95 double _double[]= {12345, 1234.5, 123.45, 12.345, 1.2345};
97 CComVariant _variant[]= {L"variant 1", L"variant2", L"variant3"};
98 wchar_t _wchar[]= {L'1', L'2', L'3', L'A', L' '};
99 BSTR _bstr[]={L"Ich", L"bin", L"ein", L"Hamburger", L"Jung"};
100 SmartArray<char> arByte( _c, 5, VT_I1);
101 SmartArray< short> arShort( _short, 5, VT_I2);
102 //SmartArray< unsigned short> arUShort( _ushort, 5, VT_UI2);
103 SmartArray< long> arLong( _long, 5, VT_I4);
104 //SmartArray< unsigned long> arULong( _ulong, 5, VT_UI4);
105 //SmartArray< float> arFloat( _float, 5, VT_R4 );
106 SmartArray< double> arDouble( _double, 5, VT_R8 );
107 //SmartArray< unsigned short> arWChar( _wchar, 5, VT_UI2 );
108 SmartArray< wchar_t* > arString( _bstr, 5, VT_BSTR);
109 SmartArray< VARIANT > arVariant( _variant, 3, VT_VARIANT);
112 HRESULT doTest()
114 HRESULT hr;
115 USES_CONVERSION;
116 CComPtr<IUnknown> spUnkMgr;
118 putenv("UNO_TYPES=types.rdb");
119 putenv("UNO_SERVICES=services.rdb");
120 Reference<XComponentContext> xContext = defaultBootstrap_InitialComponentContext();
122 Reference< XMultiComponentFactory > mgr = xContext->getServiceManager();//createRegistryServiceFactory( OUString(L"services.rdb"));
123 Reference< XInterface > xIntSupplier= mgr->createInstanceWithContext(
124 "com.sun.star.bridge.OleBridgeSupplierVar1", xContext);
125 Reference< XBridgeSupplier2 > xSuppl( xIntSupplier, UNO_QUERY);
126 Reference <XInterface> xOletest= mgr->createInstanceWithContext(
127 "oletest.OleTest", xContext);
128 Any any;
129 any <<= xOletest;
130 sal_uInt8 arId[16];
131 rtl_getGlobalProcessId( arId);
132 Any target= xSuppl->createBridge( any, Sequence<sal_Int8>( (sal_Int8*)arId, 16), UNO, OLE);
133 CComDispatchDriver oletest;
134 if (target.getValueTypeClass() == cppu::UnoType<sal_uIntPtr>::get().getTypeClass())
136 VARIANT* pVariant = *(VARIANT**)target.getValue();
138 oletest= pVariant->pdispVal;
140 VariantClear(pVariant);
141 CoTaskMemFree(pVariant);
144 CComVariant varRet;
145 CComVariant varParam1;
146 CComVariant varParam2;
147 CComVariant varParam3;
148 CComVariant varParam4;
150 long value= 100;
151 varParam1.vt= VT_I1 | VT_BYREF;
152 varParam1.plVal= &value;
154 // Testing the caching of DISPIDs and the process of acquiring member information
155 // on demand in IDispatch::Invoke
156 // Step through the corresponding IDispatch implementation of the ole bridge
157 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodByte"), &varParam1, &varRet);
158 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodByte"), &varParam1, &varRet);
159 // Name ok but different case
160 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"Testinout_methodByte"), &varParam1, &varRet);
161 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"Testinout_methodByte"), &varParam1, &varRet);
162 // not existing member
163 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"Testinout"), &varParam1, &varRet);
164 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"Testinout"), &varParam1, &varRet);
166 // Property
167 varParam1.vt= VT_ARRAY | VT_I1;
168 varParam1.parray= (SAFEARRAY*)arByte;
169 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varParam1);
170 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varParam1);
171 // Name ok but different case
172 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"attrByte"), &varParam1);
173 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"attrByte"), &varParam1);
174 // not existing member
175 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"attr"), &varParam1);
176 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"attr"), &varParam1);
178 // PropertyGet
179 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varRet);
181 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"attrByte"), &varRet);
182 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"attrByte"), &varRet);
183 //not existing member
184 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"attrBy"), &varRet);
185 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"attrBy"), &varRet);
187 DISPID dispid;
188 LPOLESTR method= L"methodByte";
189 hr = oletest.p->GetIDsOfNames(IID_NULL, &method, 1, LOCALE_USER_DEFAULT, &dispid);
192 CComVariant arg[1];
193 arg[0].vt= VT_ARRAY | VT_I1;
194 arg[0].parray= (SAFEARRAY*)arByte;
195 DISPPARAMS params={ arg,0,1,0};
197 hr = oletest.p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
198 DISPATCH_METHOD | DISPATCH_PROPERTYPUT, &params, &varRet, NULL, NULL);
200 hr = oletest.p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
201 DISPATCH_METHOD | DISPATCH_PROPERTYPUT, &params, &varRet, NULL, NULL);
203 // different case
204 LPOLESTR method2= L"MEthodByte";
205 hr = oletest.p->GetIDsOfNames(IID_NULL, &method2, 1, LOCALE_USER_DEFAULT, &dispid);
207 hr = oletest.p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
208 DISPATCH_METHOD | DISPATCH_PROPERTYPUT, &params, &varRet, NULL, NULL);
210 hr = oletest.p->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
211 DISPATCH_METHOD | DISPATCH_PROPERTYPUT, &params, &varRet, NULL, NULL);
213 LPOLESTR attrib= L"AttrByte";
214 hr = oletest.p->GetIDsOfNames(IID_NULL, &attrib, 1, LOCALE_USER_DEFAULT, &dispid);
216 hr = oletest.p->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT,
217 DISPATCH_METHOD | DISPATCH_PROPERTYPUTREF, &params, &varRet, NULL, NULL);
219 hr = oletest.p->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT,
220 DISPATCH_METHOD | DISPATCH_PROPERTYGET, &params, &varRet, NULL, NULL);
223 CComVariant varByteArray;
224 varByteArray.vt= VT_ARRAY | VT_I1;
225 varByteArray.parray= (SAFEARRAY*)arByte;
226 CComVariant varShortArray;
227 varShortArray.vt= VT_ARRAY | VT_I2;
228 varShortArray.parray= (SAFEARRAY*)arShort;
229 CComVariant varLongArray;
230 varLongArray.vt= VT_ARRAY | VT_I4;
231 varLongArray.parray= (SAFEARRAY*)arLong;
232 CComVariant varDoubleArray;
233 varDoubleArray.vt= VT_ARRAY | VT_R8;
234 varDoubleArray.parray= (SAFEARRAY*)arDouble;
235 CComVariant varStringArray;
236 varStringArray.vt= VT_ARRAY | VT_BSTR;
237 varStringArray.parray= (SAFEARRAY*)arString;
238 CComVariant varArray;
239 varArray.vt= VT_ARRAY | VT_VARIANT;
240 varArray.parray= (SAFEARRAY*)arVariant;
242 FONTDESC fd={ sizeof( fd), L"ARIAL", 10, FW_NORMAL, 0, 0, 0, 0};
245 CComPtr< IUnknown > unk1;
246 CComPtr< IUnknown > unk2;
247 CComPtr< IUnknown > unk3;
249 IUnknown* _unknown[3];
250 hr= OleCreateFontIndirect( &fd, __uuidof( IUnknown), (void**)&unk1.p);
251 hr= OleCreateFontIndirect( &fd, __uuidof( IUnknown), (void**)&unk2.p);
252 hr= OleCreateFontIndirect( &fd, __uuidof( IUnknown), (void**)&unk3.p);
253 _unknown[0]= unk1;
254 _unknown[1]= unk2;
255 _unknown[2]= unk3;
256 SmartArray<IUnknown*> arUnknown( _unknown, 3, VT_UNKNOWN);
258 CComVariant varUnkArray;
259 varUnkArray.vt= VT_ARRAY | VT_UNKNOWN;
260 varUnkArray.parray= (SAFEARRAY*)arUnknown;
262 // preparing out parameter;
263 char byteOut;
264 CComVariant varOutByte;
265 varOutByte.vt= VT_BYREF | VT_UI1;
266 V_I1REF(&varOutByte)= &byteOut;
267 short shortOut;
268 CComVariant varOutShort;
269 varOutShort.vt= VT_BYREF | VT_I2;
270 V_I2REF( &varOutShort)= &shortOut;
271 long longOut;
272 CComVariant varOutLong;
273 varOutLong.vt= VT_BYREF | VT_I4;
274 V_I4REF( &varOutLong)= &longOut;
275 double doubleOut;
276 CComVariant varOutDouble;
277 varOutDouble.vt= VT_BYREF | VT_R8;
278 V_R8REF( &varOutDouble)= &doubleOut;
279 BSTR bstrOut= NULL;
280 CComVariant varOutString;
281 varOutString.vt= VT_BYREF | VT_BSTR;
282 V_BSTRREF(&varOutString)= &bstrOut;
283 CComVariant variantOut;
284 CComVariant varOutAny;
285 varOutAny.vt= VT_BYREF | VT_VARIANT;
286 V_VARIANTREF(&varOutAny)= &variantOut;
288 CComPtr<IDispatch> dispOut;
289 CComVariant varOutXInterface;
290 varOutXInterface.vt= VT_BYREF |VT_DISPATCH;
291 V_DISPATCHREF(&varOutXInterface)= &dispOut.p;
293 // In Parameter ( all of type Sequence ###########################################################
294 OutputDebugStringA( "In parameter of type Sequence ###########################################\n"
295 "The functions return the Sequence parameter \n\n");
297 OutputDebugStringA("methodByte | Params: \n");
298 printVariant( varByteArray);
299 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodByte"), &varByteArray, &varRet);
300 OutputDebugStringA("methodByte | return value \n");
301 printVariant( varRet);
303 OutputDebugStringA("methodShort | Params: \n");
304 printVariant( varShortArray);
305 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodShort"), &varShortArray, &varRet);
306 OutputDebugStringA("methodShort | return value \n");
307 printVariant( varRet);
309 OutputDebugStringA("methodLong | Params: \n");
310 printVariant( varLongArray);
311 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodLong"), &varLongArray, &varRet);
312 OutputDebugStringA("methodLong | return value \n");
313 printVariant( varRet);
315 OutputDebugStringA("methodDouble | Params: \n");
316 printVariant( varDoubleArray);
317 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodDouble"), &varDoubleArray, &varRet);
318 OutputDebugStringA("methodDouble | return value \n");
319 printVariant( varRet);
321 OutputDebugStringA("methodString | Params: \n");
322 printVariant( varStringArray);
323 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodString"), &varStringArray, &varRet);
324 OutputDebugStringA("methodString | return value \n");
325 printVariant( varRet);
327 OutputDebugStringA("methodAny | Params: \n");
328 printVariant( varArray);
329 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodAny"), &varArray, &varRet);
330 OutputDebugStringA("methodAny | return value \n");
331 printVariant( varRet);
333 OutputDebugStringA("methodXInterface | Params: \n");
334 printVariant( varUnkArray);
335 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"methodXInterface"), &varUnkArray, &varRet);
336 OutputDebugStringA("methodAny | return value \n");
337 printVariant( varRet);
339 // Out Parameter ###########################################################################
340 OutputDebugStringA("Out parameter ###########################################\n\n");
342 OutputDebugStringA("testout_methodByte \n");
343 hr= oletest.InvokeN(static_cast<LPCOLESTR>(L"testout_methodByte"), &varOutByte, 1, &varRet);
344 OutputDebugStringA("testout_methodByte | out value: \n");
345 printVariant( varOutByte);
347 OutputDebugStringA("testout_methodShort \n");
348 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodShort"), &varOutShort, &varRet);
349 OutputDebugStringA("testout_methodShort | out value: \n");
350 printVariant( varOutShort);
352 OutputDebugStringA("testout_methodLong \n");
353 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodLong"), &varOutLong, &varRet);
354 OutputDebugStringA("testout_methodLong | out value: \n");
355 printVariant( varOutLong);
357 OutputDebugStringA("testout_methodDouble \n");
358 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodDouble"), &varOutDouble, &varRet);
359 OutputDebugStringA("testout_methodDouble | out value: \n");
360 printVariant( varOutDouble);
362 OutputDebugStringA("testout_methodString \n");
363 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodString"), &varOutString, &varRet);
364 OutputDebugStringA("testout_methodString | out value: \n");
365 printVariant( varOutString);
367 OutputDebugStringA("testout_methodAny \n");
368 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodAny"), &varOutAny, &varRet);
369 OutputDebugStringA("methodAny | out value: \n");
370 printVariant( varOutAny);
372 OutputDebugStringA("testout_methodXInterface \n");
373 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testout_methodXInterface"), &varOutXInterface, &varRet);
374 OutputDebugStringA("methodAny | out value: \n");
375 printVariant( varOutXInterface);
376 CComDispatchDriver outDisp( *varOutXInterface.ppdispVal);
377 CComVariant varAttr3;
378 outDisp.GetPropertyByName(L"AttrAny2", &varAttr3);
379 ATLTRACE("property OleTest.AttrAny2: %s", W2A(varAttr3.bstrVal));
381 OutputDebugStringA("testout_methodMulParams1 ( 2 out Parameter) \n");
382 long longOut2=0;
383 CComVariant _params[2];
384 longOut=0;
385 _params[0]= varOutLong;
386 _params[1].vt= VT_BYREF | VT_I4;
387 V_I4REF(& _params[1])= &longOut2;
388 hr= oletest.InvokeN( static_cast<LPCOLESTR>(L"testout_methodMulParams1"), (VARIANT*)&_params, 2);
389 OutputDebugStringA("testout_methodMulParams1 | out values: \n");
390 printVariant( _params[1]);
391 printVariant( _params[0]);
393 OutputDebugStringA("testout_methodMulParams2 ( 3 out Parameter) \n");
394 CComVariant _params2[3];
395 _params2[2]= varOutLong;
396 _params2[1].vt= VT_BYREF | VT_I4;
397 V_I4REF(& _params2[1])= &longOut2;
398 _params2[0]= varOutString;
399 hr= oletest.InvokeN( static_cast<LPCOLESTR>( L"testout_methodMulParams2"), (VARIANT*)&_params2, 3);
400 OutputDebugStringA("testout_methodMulParams2 | out values: \n");
401 printVariant( _params2[2]);
402 printVariant( _params2[1]);
403 printVariant( _params2[0]);
405 OutputDebugStringA("testout_methodMulParams3 ( 1 in and 1 out Parameter) \n");
406 CComVariant _params3[2];
407 _params3[1]= CComBSTR(L" In string");
408 _params3[0]= varOutString;
409 hr= oletest.InvokeN( static_cast<LPCOLESTR>( L"testout_methodMulParams3"), (VARIANT*)&_params3, 2);
410 OutputDebugStringA("testout_methodMulParams3 | out values: \n");
411 printVariant( _params3[1]);
412 printVariant( _params3[0]);
414 //In Out Parameter ###########################################################################
415 OutputDebugStringA("In Out parameter ###########################################\n\n");
417 *V_I1REF(&varOutByte)= 5;
418 ATLTRACE("testinout_methodByte | in value: %d \n", *V_I1REF(&varOutByte));
419 hr= oletest.InvokeN(static_cast<LPCOLESTR>(L"testinout_methodByte"), &varOutByte, 1, &varRet);
420 OutputDebugStringA("testinout_methodByte | out value: \n");
421 printVariant( varOutByte);
423 OutputDebugStringA("testinout_methodShort | in value= 1000 \n");
424 *V_UI2REF(&varOutShort)= 1000;
425 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodShort"), &varOutShort, &varRet);
426 OutputDebugStringA("testinout_methodShort | out value: \n");
427 printVariant( varOutShort);
429 OutputDebugStringA("testinout_methodLong | in value= 10000 \n");
430 *V_UI4REF(&varOutLong)= 10000;
431 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodLong"), &varOutLong, &varRet);
432 OutputDebugStringA("testinout_methodLong | out value: \n");
433 printVariant( varOutLong);
435 *V_R8REF(&varOutDouble)= 3.14;
436 ATLTRACE("testinou_methodDouble in value: %f \n",*V_R8REF(&varOutDouble));
437 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodDouble"), &varOutDouble, &varRet);
438 OutputDebugStringA("testinout_methodDouble | out value: \n");
439 printVariant( varOutDouble);
441 SysFreeString( *V_BSTRREF(&varOutString));
442 *V_BSTRREF(&varOutString)= SysAllocString( L"this is a in string");
443 ATLTRACE("testinout_methodString | value: %s \n", W2A(*V_BSTRREF(&varOutString)));
444 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodString"), &varOutString, &varRet);
445 OutputDebugStringA("testinout_methodString | out value: \n");
446 printVariant( varOutString);
448 CComVariant var1(CComBSTR(L" this is a string in a VARIANT"));
449 CComVariant outVar1;
450 outVar1.vt= VT_BYREF | VT_VARIANT;
451 outVar1.pvarVal= &var1;
452 ATLTRACE("testinout_methodAny | parameter: %s\n", W2A(var1.bstrVal));
453 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodAny"), &varOutAny, &varRet);
454 OutputDebugStringA("testinout_methodAny | out value: \n");
455 printVariant( varOutAny);
457 CComPtr< IUnknown > objectIn = unk1;
458 CComVariant varOutIFace;
459 varOutIFace.vt= VT_BYREF | VT_UNKNOWN;
460 varOutIFace.ppunkVal= &objectIn.p;
461 (*varOutIFace.ppunkVal)->AddRef();
462 OutputDebugStringA("testinout_methodXInterface | in value: \n");
463 printVariant(varOutIFace);
464 hr= oletest.Invoke1(static_cast<LPCOLESTR>(L"testinout_methodXInterface"), &varOutIFace, &varRet);
465 OutputDebugStringA("testinout_methodXInterface | out value: \n");
466 printVariant( varOutIFace);
468 // Properties ######################################################################
469 OutputDebugStringA(" Properties ###########################################\n\n");
471 OutputDebugStringA("set property \"AttrByte\" | value");
472 //CComVariant propArByte;
473 //propArByte.vt= VT_ARRAY | VT_I1;
474 varParam1.parray= (SAFEARRAY*)arByte;
475 printVariant( varParam1);
476 hr= oletest.PutPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varParam1);
477 OutputDebugStringA("get property \"AttrByte\" | value:");
478 varRet.Clear();
479 hr= oletest.GetPropertyByName( static_cast<LPCOLESTR>(L"AttrByte"), &varRet);
480 printVariant( varRet);
483 return S_OK;
489 void printVariant( VARIANT & _var)
491 HRESULT hr;
492 USES_CONVERSION;
493 CComVariant var;
494 hr= VariantCopyInd( &var, &_var);
495 if( var.vt & VT_ARRAY)
497 VARTYPE type= var.vt ^ VT_ARRAY;
498 SAFEARRAY * sarray= var.parray;
499 long lbound;
500 long ubound;
501 hr= SafeArrayGetLBound( sarray, 1, &lbound);
502 hr= SafeArrayGetUBound( sarray, 1, &ubound);
503 long count= ubound - lbound + 1;
504 char charValue;
505 BYTE byteValue;
506 short shortValue;
507 long longValue;
508 double doubleValue;
509 IUnknown* unkValue;
510 BSTR bstrValue;
511 OutputDebugStringA("# Array \n");
512 for( long i= 0; i < count; i++)
514 // CComVariant variantValue;
515 CHAR buf[256];
516 wsprintfA( buf, "%d : ", i);
517 OutputDebugStringA( buf);
518 VARIANT varTemp;
519 VariantInit( &varTemp);
520 VARIANT variantValue;
521 VariantInit( &variantValue);
522 switch( type)
524 case VT_UI1:
525 hr= SafeArrayGetElement( sarray, &i, &byteValue);
526 varTemp.vt= VT_UI1;
527 V_UI1( &varTemp)= byteValue;
528 printVariant( varTemp);
529 break;
530 case VT_I1:
531 hr= SafeArrayGetElement( sarray, &i, &charValue);
532 varTemp.vt= VT_I1;
533 V_I1( &varTemp)= charValue;
534 printVariant( varTemp);
535 break;
536 case VT_I2:
537 hr= SafeArrayGetElement( sarray, &i, &shortValue);
538 varTemp.vt= VT_I2;
539 V_I2( &varTemp)= shortValue;
540 printVariant( varTemp);
541 break;
543 case VT_UI2:
544 case VT_I4:
545 hr= SafeArrayGetElement( sarray, &i, &longValue);
546 varTemp.vt= VT_I4;
547 V_I4( &varTemp)= longValue;
548 printVariant( varTemp);
549 break;
550 case VT_R8:
551 hr= SafeArrayGetElement( sarray, &i, &doubleValue);
552 varTemp.vt= VT_R8;
553 V_R8( &varTemp)= doubleValue;
554 printVariant( varTemp);
555 break;
556 case VT_BSTR:
557 hr= SafeArrayGetElement( sarray, &i, &bstrValue);
558 varTemp.vt= VT_BSTR;
559 varTemp.bstrVal= bstrValue;
560 printVariant( varTemp);
561 break;
562 case VT_VARIANT:
563 hr= SafeArrayGetElement( sarray, &i, &varTemp);
564 printVariant( varTemp);
565 break;
567 case VT_UNKNOWN:
568 hr= SafeArrayGetElement( sarray, &i, &unkValue);
569 varTemp.vt= VT_UNKNOWN;
570 varTemp.punkVal= unkValue;
571 printVariant( varTemp);
572 break;
575 VariantClear( &varTemp);
576 VariantClear( &variantValue);
580 else
582 CHAR buf[256];
583 switch (var.vt)
585 case VT_I1: wsprintfA( buf, " VT_I1: %d \n", V_I1( &var) );
586 break;
587 case VT_UI1: wsprintfA( buf, " VT_UI1: %d \n", V_I1( &var) );
588 break;
590 case VT_I2: wsprintfA( buf, " VT_I2: %d \n", V_I2( &var) );
591 break;
592 case VT_I4: wsprintfA( buf, " VT_I4: %d \n", V_I4( &var) );
593 break;
594 case VT_R8:
597 // int decimal, sign;
598 // char *buffer;
599 // int precision = 14;
600 // double source = 3.1415926535;
602 // buffer = _ecvt( V_R8(&var), precision, &decimal, &sign );
603 sprintf( buf, " VT_R8: %f \n",V_R8( &var) );
604 break;
606 case VT_UNKNOWN:
607 // The object implement IFont
609 CComDispatchDriver disp( var.punkVal);
610 CComVariant ret;
611 hr= disp.GetPropertyByName( static_cast<LPCOLESTR>(L"Name"), &ret);
612 wsprintfA( buf, " VT_UNKNOWN: property \"Name\": %s \n", W2A(ret.bstrVal));
613 break;
615 case VT_DISPATCH:
616 // The object implement IFont
618 CComDispatchDriver disp( var.punkVal);
619 CComVariant ret;
620 if( SUCCEEDED( hr= disp.GetPropertyByName( static_cast<LPCOLESTR>(L"Name"), &ret)))
621 wsprintfA( buf, " VT_DISPATCH: property \"Name\": %s \n", W2A(ret.bstrVal));
622 else
623 wsprintfA( buf, " VT_DISPATCH \n");
625 break;
629 case VT_BSTR:
631 CHAR* str= W2A( var.bstrVal);
632 wsprintfA( buf, " VT_BSTR: %s \n", str);
634 break;
635 default:
636 wsprintfA( buf, "\n");
640 OutputDebugStringA( buf);
643 return;
647 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */