bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / test / ole / AxTestComponents / Basic.cpp
blob2406ba12f0c75e740de8d3168a5ec357a0a429b2
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 .
20 #include "stdafx.h"
21 #include "Basic.h"
25 // CBasic
26 CBasic::CBasic(): m_cPrpByte(0),m_nPrpShort(0),m_lPrpLong(0),m_fPrpFloat(0), m_dPrpDouble(0),m_PrpArray(0),
27 m_safearray(NULL), m_bool(VARIANT_FALSE),
28 m_arByte(0), m_arShort(0), m_arLong(0), m_arString(0), m_arVariant(0), m_arFloat(0),
29 m_arDouble(0), m_arObject(0), m_arByteDim2(0), m_date(0.), m_scode(0)
32 memset(&m_cy, 0, sizeof(CY));
33 memset(&m_decimal, 0, sizeof(DECIMAL));
36 CBasic::~CBasic()
38 SafeArrayDestroy(m_safearray);
39 SafeArrayDestroy(m_arByte);
40 SafeArrayDestroy(m_arShort);
41 SafeArrayDestroy(m_arLong);
42 SafeArrayDestroy(m_arString);
43 SafeArrayDestroy(m_arVariant);
44 SafeArrayDestroy(m_arFloat);
45 SafeArrayDestroy(m_arDouble);
46 SafeArrayDestroy(m_arObject);
47 SafeArrayDestroy(m_arByteDim2);
50 STDMETHODIMP CBasic::inBool(VARIANT_BOOL val)
52 m_bool = val;
53 return S_OK;
55 STDMETHODIMP CBasic::inByte(unsigned char val)
57 m_byte = val;
58 return S_OK;
61 STDMETHODIMP CBasic::inShort(short val)
63 m_short = val;
64 return S_OK;
67 STDMETHODIMP CBasic::inLong(long val)
69 m_long = val;
70 return S_OK;
73 STDMETHODIMP CBasic::inString(BSTR val)
75 m_bstr = val;
76 return S_OK;
79 STDMETHODIMP CBasic::inFloat(float val)
81 m_float = val;
82 return S_OK;
85 STDMETHODIMP CBasic::inDouble(double val)
87 m_double = val;
89 CComVariant varDest;
90 CComVariant varSource(val);
91 HRESULT hr = VariantChangeType(&varDest, &varSource, 0, VT_BSTR);
92 return S_OK;
95 STDMETHODIMP CBasic::inVariant(VARIANT val)
97 m_var1 = val;
98 return S_OK;
101 STDMETHODIMP CBasic::inArray(LPSAFEARRAY val)
103 HRESULT hr = S_OK;
104 if (FAILED(hr = SafeArrayDestroy(m_safearray)))
105 return hr;
106 if (FAILED(hr = SafeArrayCopy(val, &m_safearray)))
107 return hr;
108 return S_OK;
111 STDMETHODIMP CBasic::inObject(IDispatch *val)
113 m_obj = val;
114 return S_OK;
117 STDMETHODIMP CBasic::inoutBool(VARIANT_BOOL* val)
119 VARIANT_BOOL aBool = *val;
120 *val = m_bool;
121 m_bool = aBool;
122 return S_OK;
126 STDMETHODIMP CBasic::inoutByte(unsigned char* val)
128 unsigned char aByte = *val;
129 *val = m_byte;
130 m_byte = aByte;
131 return S_OK;
134 STDMETHODIMP CBasic::inoutShort(short *val)
136 short aShort = *val;
137 *val = m_short;
138 m_short = aShort;
139 return S_OK;
142 STDMETHODIMP CBasic::inoutLong(long *val)
144 long aLong = *val;
145 *val = m_long;
146 m_long = aLong;
147 return S_OK;
150 STDMETHODIMP CBasic::inoutString(BSTR *val)
152 CComBSTR aStr = *val;
153 HRESULT hr = S_OK;
154 if (FAILED( hr = m_bstr.CopyTo(val)))
155 return hr;
156 m_bstr = aStr;
157 return S_OK;
160 STDMETHODIMP CBasic::inoutFloat(float *val)
162 float aFloat = *val;
163 *val = m_float;
164 m_float = aFloat;
165 return S_OK;
168 STDMETHODIMP CBasic::inoutDouble(double *val)
170 double aDouble = *val;
171 *val = m_double;
172 m_double = aDouble;
173 return S_OK;
176 STDMETHODIMP CBasic::inoutVariant(VARIANT *val)
178 CComVariant aVar = *val;
179 HRESULT hr = S_OK;
180 if (FAILED(hr = VariantCopy(val, &m_var1)))
181 return hr;
182 m_var1 = aVar;
183 return S_OK;
186 /* The array contains VARIANT according to IDL.
187 If the VARIANTs contain strings then we append "out" to each string.
189 STDMETHODIMP CBasic::inoutArray(LPSAFEARRAY *val)
191 SAFEARRAY* aAr = NULL;
192 HRESULT hr = S_OK;
193 if (FAILED(hr = SafeArrayCopy(*val, &aAr)))
194 return hr;
195 if (FAILED(hr = SafeArrayCopy(m_safearray, val)))
196 return hr;
197 if (FAILED(hr = SafeArrayCopy(aAr, & m_safearray)))
198 return hr;
199 return S_OK;
202 STDMETHODIMP CBasic::inoutObject(IDispatch **val)
204 CComPtr<IDispatch> disp = *val;
205 if (*val)
206 (*val)->Release();
207 *val = m_obj;
208 if (*val)
209 (*val)->AddRef();
210 m_obj = disp;
211 return S_OK;
215 STDMETHODIMP CBasic::outBool(VARIANT_BOOL* val)
217 *val = m_bool;
218 return S_OK;
221 STDMETHODIMP CBasic::outByte(unsigned char *val)
223 *val= m_byte;
224 return S_OK;
227 STDMETHODIMP CBasic::outShort(short *val)
229 *val= m_short;
230 return S_OK;
233 STDMETHODIMP CBasic::outLong(long *val)
235 *val= m_long;
236 return S_OK;
239 STDMETHODIMP CBasic::outString(BSTR *val)
241 *val= SysAllocString(m_bstr);
242 return S_OK;
245 STDMETHODIMP CBasic::outFloat(float *val)
247 *val= m_float;
248 return S_OK;
251 STDMETHODIMP CBasic::outDouble(double *val)
253 *val= m_double;
254 return S_OK;
257 STDMETHODIMP CBasic::outVariant(VARIANT *val)
259 HRESULT hr = S_OK;
260 if (FAILED(hr = VariantCopy(val, &m_var1)))
261 return hr;
262 return S_OK;
265 STDMETHODIMP CBasic::outArray(LPSAFEARRAY *val)
267 HRESULT hr = S_OK;
268 if (FAILED(hr = SafeArrayCopy(m_safearray, val)))
269 return false;
270 return S_OK;
273 STDMETHODIMP CBasic::outObject(IDispatch* *val)
275 *val = m_obj;
276 if (m_obj)
277 (*val)->AddRef();
279 return S_OK;
283 STDMETHODIMP CBasic::get_prpBool(VARIANT_BOOL* pVal)
285 if (!pVal) return E_POINTER;
286 *pVal = m_bool;
287 return S_OK;
290 STDMETHODIMP CBasic::put_prpBool(VARIANT_BOOL val)
292 m_bool = val;
293 return S_OK;
297 STDMETHODIMP CBasic::get_prpByte(unsigned char *pVal)
299 if( !pVal)
300 return E_POINTER;
301 *pVal= m_cPrpByte;
302 return S_OK;
305 STDMETHODIMP CBasic::put_prpByte(unsigned char newVal)
307 m_cPrpByte= newVal;
308 return S_OK;
311 STDMETHODIMP CBasic::get_prpShort(short *pVal)
313 if( !pVal)
314 return E_POINTER;
315 *pVal= m_nPrpShort;
316 return S_OK;
319 STDMETHODIMP CBasic::put_prpShort(short newVal)
321 m_nPrpShort= newVal;
322 return S_OK;
325 STDMETHODIMP CBasic::get_prpLong(long *pVal)
327 if( !pVal)
328 return E_POINTER;
329 *pVal= m_lPrpLong;
330 return S_OK;
333 STDMETHODIMP CBasic::put_prpLong(long newVal)
335 m_lPrpLong= newVal;
336 return S_OK;
339 STDMETHODIMP CBasic::get_prpString(BSTR *pVal)
341 if( !pVal)
342 return E_POINTER;
343 m_bstrPrpString.CopyTo( pVal );
344 return S_OK;
347 STDMETHODIMP CBasic::put_prpString(BSTR newVal)
349 m_bstrPrpString= newVal;
350 return S_OK;
353 STDMETHODIMP CBasic::get_prpFloat(float *pVal)
355 if( !pVal)
356 return E_POINTER;
357 *pVal= m_fPrpFloat;
358 return S_OK;
361 STDMETHODIMP CBasic::put_prpFloat(float newVal)
363 m_fPrpFloat= newVal;
364 return S_OK;
367 STDMETHODIMP CBasic::get_prpDouble(double *pVal)
369 if( !pVal)
370 return E_POINTER;
371 *pVal= m_dPrpDouble;
372 return S_OK;
375 STDMETHODIMP CBasic::put_prpDouble(double newVal)
377 m_dPrpDouble= newVal;
378 return S_OK;
381 STDMETHODIMP CBasic::get_prpVariant(VARIANT *pVal)
383 if( !pVal)
384 return E_POINTER;
385 HRESULT hr = S_OK;
386 if (FAILED(hr = VariantCopy( pVal, &m_PropVariant)))
387 return hr;
388 return hr;
391 STDMETHODIMP CBasic::put_prpVariant(VARIANT newVal)
393 m_PropVariant= newVal;
394 return S_OK;
397 STDMETHODIMP CBasic::get_prpArray(LPSAFEARRAY *pVal)
399 if( !pVal)
400 return E_POINTER;
401 HRESULT hr = S_OK;
402 if (FAILED(hr = SafeArrayCopy( m_PrpArray, pVal)))
403 return hr;
404 return hr;
407 STDMETHODIMP CBasic::put_prpArray(LPSAFEARRAY newVal)
409 HRESULT hr = S_OK;
410 if (FAILED(hr = SafeArrayDestroy( m_PrpArray)))
411 return hr;
412 if (FAILED(hr = SafeArrayCopy( newVal, &m_PrpArray)))
413 return hr;
414 return hr;
417 STDMETHODIMP CBasic::get_prpObject(IDispatch **pVal)
419 if( !pVal)
420 return E_POINTER;
421 *pVal= m_PrpObject;
422 if( *pVal != NULL)
423 (*pVal)->AddRef();
424 return S_OK;
427 STDMETHODIMP CBasic::put_prpObject(IDispatch *newVal)
429 m_PrpObject= newVal;
430 return S_OK;
433 STDMETHODIMP CBasic::mixed1(
434 /* [out][in] */ unsigned char *aChar,
435 /* [out][in] */ float *aFloat,
436 /* [out][in] */ VARIANT *aVar)
439 HRESULT hr= S_OK;
440 inoutByte(aChar);
441 inoutFloat(aFloat);
442 inoutVariant(aVar);
443 return hr;
449 // VT_UI1
451 STDMETHODIMP CBasic::inSequenceLong(LPSAFEARRAY val)
453 HRESULT hr = S_OK;
454 if (FAILED(hr = SafeArrayDestroy(m_arLong)))
455 return hr;
456 if (FAILED(hr = SafeArrayCopy(val, & m_arLong)))
457 return hr;
458 return hr;
461 STDMETHODIMP CBasic::inSequenceByte( LPSAFEARRAY val)
463 HRESULT hr = S_OK;
464 if (FAILED(hr = SafeArrayDestroy(m_arByte)))
465 return hr;
466 if (FAILED(hr = SafeArrayCopy(val, & m_arByte)))
467 return hr;
468 return hr;
471 STDMETHODIMP CBasic::inSequenceShort(LPSAFEARRAY val)
473 HRESULT hr = S_OK;
474 if (FAILED(hr = SafeArrayDestroy(m_arShort)))
475 return hr;
476 if (FAILED(hr = SafeArrayCopy(val, & m_arShort)))
477 return hr;
478 return hr;
481 STDMETHODIMP CBasic::inSequenceString(LPSAFEARRAY val)
483 HRESULT hr = S_OK;
484 if (FAILED(hr = SafeArrayDestroy(m_arString)))
485 return hr;
486 if (FAILED(hr = SafeArrayCopy(val, & m_arString)))
487 return hr;
488 return hr;
491 STDMETHODIMP CBasic::inSequenceFloat(LPSAFEARRAY val)
493 HRESULT hr = S_OK;
494 if (FAILED(hr = SafeArrayDestroy(m_arFloat)))
495 return hr;
496 if (FAILED(hr = SafeArrayCopy(val, & m_arFloat)))
497 return hr;
498 return hr;
501 STDMETHODIMP CBasic::inSequenceDouble(LPSAFEARRAY val)
503 HRESULT hr = S_OK;
504 if (FAILED(hr = SafeArrayDestroy(m_arDouble)))
505 return hr;
506 if (FAILED(hr = SafeArrayCopy(val, & m_arDouble)))
507 return hr;
508 return hr;
511 STDMETHODIMP CBasic::inSequenceObject(LPSAFEARRAY val)
513 HRESULT hr = S_OK;
514 if (FAILED(hr = SafeArrayDestroy(m_arObject)))
515 return hr;
516 if (FAILED(hr = SafeArrayCopy(val, & m_arObject)))
517 return hr;
518 return hr;
521 void CBasic::printArray( LPSAFEARRAY val, BSTR message, VARTYPE type)
524 HRESULT hr= S_OK;
525 USES_CONVERSION;
526 long lbound=0;
527 long ubound= 0;
528 hr= SafeArrayGetLBound( val, 1, &lbound);
529 hr= SafeArrayGetUBound( val, 1, &ubound);
530 long length= ubound - lbound +1;
532 CComVariant varElement;
533 char buf[1024];
534 sprintf( buf,"%s", W2A(message));
536 for( long i= 0; i < length ; i++)
538 char tmp[1024];
539 long data=0;
540 CComVariant var;
541 switch( type)
543 case VT_UI1:
544 case VT_I2:
545 case VT_I4:
546 case VT_ERROR:
547 hr= SafeArrayGetElement( val, &i, (void*)&data);
548 sprintf( tmp, "%ld \n", *(long*)&data);
549 break;
550 case VT_BSTR:
551 hr= SafeArrayGetElement( val, &i, (void*)&data);
552 sprintf( tmp, "%S \n", (BSTR)data);
553 break;
554 case VT_VARIANT:
555 hr= SafeArrayGetElement( val, &i, &var);
556 sprintf( tmp, "%x \n", var.byref);
557 break;
558 case VT_R4:
559 hr= SafeArrayGetElement( val, &i, (void*)&data);
560 sprintf( tmp, "%f \n", *(float*) &data);
561 break;
562 case VT_R8: ;
563 hr= SafeArrayGetElement( val, &i, (void*)&data);
564 sprintf( tmp, "%f \n", *(double*) &data);
565 break;
566 case VT_DISPATCH:
567 // we assume the objects are instances of this component and have the
568 // property prpString set.
569 hr= SafeArrayGetElement( val, &i, (void*)&data);
570 IDispatch* pdisp= ( IDispatch*) data;
571 CComDispatchDriver driver( pdisp);
572 CComVariant var;
573 if( pdisp)
575 driver.GetPropertyByName(L"prpString", &var);
576 sprintf( tmp, "%x : %S \n", *(long*)&data, var.bstrVal);
578 else
579 sprintf( tmp, "%x\n", *(long*)&data);
582 strcat( buf, tmp);
584 MessageBox( NULL, _T(A2T(buf)), _T("AxTestComponents.Basic"), MB_OK);
587 // V_ERROR OLECHAR VARIANT VT_UI1
589 STDMETHODIMP CBasic::outSequenceByte(LPSAFEARRAY* val)
591 HRESULT hr= S_OK;
592 hr = SafeArrayCopy(m_arByte, val);
593 return hr;
596 STDMETHODIMP CBasic::outSequenceShort(LPSAFEARRAY* val)
598 HRESULT hr= S_OK;
599 hr = SafeArrayCopy(m_arShort, val);
600 return hr;
603 STDMETHODIMP CBasic::outSequenceLong(LPSAFEARRAY* val)
605 HRESULT hr= S_OK;
606 hr = SafeArrayCopy(m_arLong, val);
607 return hr;
610 STDMETHODIMP CBasic::outSequenceString(LPSAFEARRAY* val)
612 HRESULT hr= S_OK;
613 hr = SafeArrayCopy(m_arString, val);
614 return hr;
617 STDMETHODIMP CBasic::outSequenceFloat(LPSAFEARRAY* val)
619 HRESULT hr= S_OK;
620 hr = SafeArrayCopy(m_arFloat, val);
621 return hr;
624 STDMETHODIMP CBasic::outSequenceDouble(LPSAFEARRAY* val)
626 HRESULT hr= S_OK;
627 hr = SafeArrayCopy(m_arDouble, val);
628 return hr;
631 STDMETHODIMP CBasic::outSequenceObject(LPSAFEARRAY* val)
633 HRESULT hr = S_OK;
634 hr = SafeArrayCopy(m_arObject, val);
635 return S_OK;
638 STDMETHODIMP CBasic::inoutSequenceByte(LPSAFEARRAY* val)
640 HRESULT hr = S_OK;
641 SAFEARRAY *arTemp = NULL;
642 if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
643 return hr;
644 if (FAILED(hr = SafeArrayCopy(m_arByte, val)))
645 return hr;
646 m_arByte = arTemp;
647 return hr;
650 STDMETHODIMP CBasic::inoutSequenceShort(LPSAFEARRAY* val)
652 HRESULT hr = S_OK;
653 SAFEARRAY *arTemp = NULL;
654 if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
655 return hr;
656 if (FAILED(hr = SafeArrayCopy(m_arShort, val)))
657 return hr;
658 m_arShort = arTemp;
659 return hr;
662 STDMETHODIMP CBasic::inoutSequenceLong(LPSAFEARRAY* val)
664 HRESULT hr = S_OK;
665 SAFEARRAY *arTemp = NULL;
666 if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
667 return hr;
668 if (FAILED(hr = SafeArrayCopy(m_arLong, val)))
669 return hr;
670 m_arLong = arTemp;
671 return hr;
674 STDMETHODIMP CBasic::inoutSequenceString(LPSAFEARRAY* val)
676 HRESULT hr = S_OK;
677 SAFEARRAY *arTemp = NULL;
678 if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
679 return hr;
680 if (FAILED(hr = SafeArrayCopy(m_arString, val)))
681 return hr;
682 m_arString = arTemp;
683 return hr;
686 STDMETHODIMP CBasic::inoutSequenceFloat(LPSAFEARRAY* val)
688 HRESULT hr = S_OK;
689 SAFEARRAY *arTemp = NULL;
690 if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
691 return hr;
692 if (FAILED(hr = SafeArrayCopy(m_arFloat, val)))
693 return hr;
694 m_arFloat = arTemp;
695 return hr;
698 STDMETHODIMP CBasic::inoutSequenceDouble(LPSAFEARRAY* val)
700 HRESULT hr = S_OK;
701 SAFEARRAY *arTemp = NULL;
702 if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
703 return hr;
704 if (FAILED(hr = SafeArrayCopy(m_arDouble, val)))
705 return hr;
706 m_arDouble = arTemp;
707 return hr;
710 STDMETHODIMP CBasic::inoutSequenceObject(LPSAFEARRAY* val)
712 HRESULT hr = S_OK;
713 SAFEARRAY *arTemp = NULL;
714 if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
715 return hr;
716 if (FAILED(hr = SafeArrayCopy(m_arObject, val)))
717 return hr;
718 m_arObject = arTemp;
719 return hr;
722 // 2-dimensional Array
723 STDMETHODIMP CBasic::inMulDimArrayLong(LPSAFEARRAY val)
725 printMulArray( val, VT_I4);
726 return S_OK;
728 // 2-dimensional Array
729 STDMETHODIMP CBasic::inMulDimArrayVariant(LPSAFEARRAY val)
731 printMulArray( val, VT_VARIANT);
732 return S_OK;
734 // 3-dimensional Array
735 STDMETHODIMP CBasic::inMulDimArrayLong2(LPSAFEARRAY val)
737 printMulArray( val, VT_I4);
738 return S_OK;
740 // 3-dimensional Array
741 STDMETHODIMP CBasic::inMulDimArrayVariant2(LPSAFEARRAY val)
743 return S_OK;
747 STDMETHODIMP CBasic::inMulDimArrayByte(LPSAFEARRAY val)
749 HRESULT hr = S_OK;
750 if (FAILED(hr = SafeArrayDestroy(m_arByteDim2)))
751 return hr;
752 if (FAILED(hr = SafeArrayCopy(val, & m_arByteDim2)))
753 return hr;
754 return hr;
756 // 3-dimensionales array
757 STDMETHODIMP CBasic::inMulDimArrayByte2(LPSAFEARRAY val)
760 // TODO: Add your implementation code here
761 //printMulArray( val, VT_UI1);
762 return S_OK;
765 // supports 2 and 3 dimensionals SAFEARRAY with elements of long or VARIANT
766 void CBasic::printMulArray( SAFEARRAY* val, VARTYPE type)
768 HRESULT hr= S_OK;
769 UINT dims= SafeArrayGetDim( val);
770 long lbound1;
771 long ubound1;
772 long lbound2;
773 long ubound2;
774 long lbound3;
775 long ubound3;
776 long length1;
777 long length2;
779 char buff[4096];
780 buff[0]=0;
782 if( dims == 2)
784 hr= SafeArrayGetLBound( val, 1, &lbound1);
785 hr= SafeArrayGetUBound( val, 1, &ubound1);
786 length1= ubound1 - lbound1 +1;
788 hr= SafeArrayGetLBound( val, 2, &lbound2);
789 hr= SafeArrayGetUBound( val, 2, &ubound2);
790 length2= ubound2 - lbound2 + 1;
791 char tmpBuf[1024];
792 tmpBuf[0]=0;
793 long index[2];
794 for( long i= 0; i< length2; i++)
796 for( long j= 0; j<length1; j++)
798 index[0]= j;
799 index[1]= i;
800 long longVal;
801 CComVariant var;
802 switch( type)
804 case VT_I4:
805 hr= SafeArrayGetElement( val, index, &longVal);
806 sprintf( tmpBuf, "(%ld,%ld): %ld\n", index[1], index[0], longVal);
807 break;
808 case VT_UI1:
809 hr= SafeArrayGetElement( val, index, &longVal);
810 sprintf( tmpBuf, "(%ld,%ld): %d\n", index[1], index[0], (unsigned char)longVal);
811 break;
812 case VT_VARIANT:
813 hr= SafeArrayGetElement( val, index, &var );
814 sprintf( tmpBuf, "(%ld,%ld): %d (vartype %d)\n", index[1], index[0], var.byref, var.vt);
815 break;
817 strcat( buff,tmpBuf);
824 else if( dims == 3 )
826 hr= SafeArrayGetLBound( val, 1, &lbound1);
827 hr= SafeArrayGetUBound( val, 1, &ubound1);
828 length1= ubound1 - lbound1 +1;
830 hr= SafeArrayGetLBound( val, 2, &lbound2);
831 hr= SafeArrayGetUBound( val, 2, &ubound2);
832 length2= ubound2 - lbound2 + 1;
834 hr= SafeArrayGetLBound( val, 3, &lbound3);
835 hr= SafeArrayGetUBound( val, 3, &ubound3);
836 long length3= ubound3 - lbound3 +1;
837 char tmpBuf[1024];
838 tmpBuf[0]=0;
839 long index[3];
840 for( long i= 0; i< length3; i++)
842 for( long j= 0; j<length2; j++)
844 for( long k= 0; k<length1; k++)
846 index[0]= k;
847 index[1]= j;
848 index[2]= i;
849 long longVal;
850 CComVariant var;
851 switch( type)
853 case VT_I4:
854 hr= SafeArrayGetElement( val, index, &longVal);
855 sprintf( tmpBuf, "(%ld,%ld,%ld): %ld\n", index[2], index[1], index[0], longVal);
856 break;
857 case VT_UI1:
858 hr= SafeArrayGetElement( val, index, &longVal);
859 sprintf( tmpBuf, "(%ld,%ld,%ld): %d\n", index[2], index[1], index[0], (unsigned char)longVal);
860 break;
862 case VT_VARIANT:
863 hr= SafeArrayGetElement( val, index, &var );
864 sprintf( tmpBuf, "(%ld,%ld,%ld): %d (vartype %d)\n", index[2], index[1], index[0], var.byref, var.vt);
865 break;
867 strcat( buff,tmpBuf);
875 MessageBox( NULL, A2T( buff), _T("AxTestControl.Basic"), MB_OK);
883 STDMETHODIMP CBasic::outMore(long* val1, long* val2)
885 // TODO: Add your implementation code here
886 *val1= 111;
887 *val2= 112;
888 return S_OK;
890 // If an optional parameter was not provided then the respective member will
891 // not be set
892 STDMETHODIMP CBasic::optional1(/*[in]*/ long val1, /*[in, optional]*/ VARIANT* val2)
894 m_long = val1;
895 if (val2->vt != VT_ERROR)
896 m_var1 = *val2;
897 return S_OK;
900 STDMETHODIMP CBasic::optional2(/*[out]*/ long* val1,/*[out, optional]*/ VARIANT* val2)
902 HRESULT hr = S_OK;
903 *val1 = m_long;
905 if (val2->vt != VT_ERROR)
906 hr = VariantCopy(val2, & m_var1);
907 return hr;
910 STDMETHODIMP CBasic::optional3(/*[in, optional]*/ VARIANT* val1,/*[in, optional]*/ VARIANT* val2)
912 //if (val1->vt != VT_ERROR)
913 m_var1 = *val1;
915 //if (val2->vt != VT_ERROR)
916 m_var2 = *val2;
917 return S_OK;
920 STDMETHODIMP CBasic::optional4(/*[in, out, optional]*/ VARIANT* val1,
921 /*[in, out, optional]*/ VARIANT* val2)
923 HRESULT hr = S_OK;
924 //return the previously set in values
925 if (val1->vt != VT_ERROR)
927 CComVariant var1(*val1);
928 if (FAILED(hr = VariantCopy(val1, & m_var1)))
929 return hr;
930 m_var1 = var1;
932 if (val2->vt != VT_ERROR)
934 CComVariant var2(*val2);
935 if (FAILED(hr = VariantCopy(val2, & m_var2)))
936 return hr;
937 m_var2 = var2;
939 return hr;
942 STDMETHODIMP CBasic::optional5(/*[out, optional]*/ VARIANT* val1,
943 /*[out, optional]*/ VARIANT* val2)
945 HRESULT hr = S_OK;
946 if (FAILED(hr = VariantCopy(val1, &m_var1)))
947 return hr;
948 if (FAILED(hr = VariantCopy(val2, &m_var2)))
949 return hr;
950 return hr;
953 STDMETHODIMP CBasic::defaultvalue1(/*[in, defaultvalue(10)]*/ long val1,
954 /*[in, defaultvalue(3.14)]*/ double* val2,
955 // /*[in, defaultvalue(10)]*/ VARIANT val3,
956 /*[in, defaultvalue(100)]*/ VARIANT* val4)
958 m_long = val1;
959 m_double = *val2;
960 // m_var1 = val3;
961 m_var2 = *val4;
962 return S_OK;
964 STDMETHODIMP CBasic::defaultvalue2(/*[in, out, defaultvalue(10)]*/ long* val1,
965 /*[in, out, defaultvalue(3.14)]*/ double* val2,
966 // /*[in, out, defaultvalue(10)]*/ VARIANT* val3,
967 /*[in, out, defaultvalue(100)]*/ VARIANT* val4)
969 HRESULT hr = S_OK;
970 long aLong = *val1;
971 double aDouble = *val2;
972 // CComVariant var1(*val3);
973 CComVariant var2(*val4);
974 *val1 = m_long;
975 *val2 = m_double;
976 //if (FAILED(hr = VariantCopy(val3, &m_var1)))
977 // return hr;
978 if (FAILED(hr = VariantCopy(val4, &m_var2)))
979 return hr;
980 m_long = aLong;
981 m_double = aDouble;
982 // m_var1 = var1;
983 m_var2 = var2;
984 return hr;
986 /* val2 contains the variable argument list. If no such arguments are supplied
987 then the safearray is invalid. SafeArrayCopy then returns E_INVALIDARG
989 STDMETHODIMP CBasic::varargfunc1(/*[in]*/ long val1,/*[in]*/ LPSAFEARRAY val2)
991 m_long = val1;
993 HRESULT hr = S_OK;
994 if (FAILED(hr = SafeArrayDestroy(m_safearray)))
995 return hr;
996 if (FAILED(hr = SafeArrayCopy(val2, & m_safearray)))
998 if (hr != E_INVALIDARG)
999 return hr;
1001 return S_OK;
1004 STDMETHODIMP CBasic::varargfunc2(/*[out]*/ long* val1, /*[out]*/ SAFEARRAY ** val2)
1006 *val1 = m_long;
1007 HRESULT hr = SafeArrayCopy(m_safearray, val2);
1008 return hr;
1011 STDMETHODIMP CBasic::inSequenceByteDim2(LPSAFEARRAY val)
1013 HRESULT hr = S_OK;
1014 if (FAILED(hr = SafeArrayDestroy(m_arByteDim2)))
1015 return hr;
1016 if (FAILED(hr = SafeArrayCopy(val, & m_arByteDim2)))
1017 return hr;
1018 return hr;
1022 STDMETHODIMP CBasic::inCurrency(CY val)
1024 m_cy = val;
1025 return S_OK;
1028 STDMETHODIMP CBasic::outCurrency(CY* val)
1030 *val = m_cy;
1031 return S_OK;
1034 STDMETHODIMP CBasic::inoutCurrency(CY* val)
1036 CY tmp = *val;
1037 *val = m_cy;
1038 m_cy = tmp;
1039 return S_OK;
1042 STDMETHODIMP CBasic::inDate(DATE val)
1044 m_date = val;
1045 return S_OK;
1048 STDMETHODIMP CBasic::outDate(DATE* val)
1050 *val = m_date;
1051 return S_OK;
1054 STDMETHODIMP CBasic::inoutDate(DATE* val)
1056 DATE tmp = *val;
1057 *val = m_date;
1058 m_date = tmp;
1059 return S_OK;
1062 STDMETHODIMP CBasic::get_prpCurrency(CY* pVal)
1064 *pVal = m_cy;
1065 return S_OK;
1068 STDMETHODIMP CBasic::put_prpCurrency(CY newVal)
1070 m_cy = newVal;
1071 return S_OK;
1074 STDMETHODIMP CBasic::get_prpDate(DATE* pVal)
1076 *pVal = m_date;
1077 return S_OK;
1080 STDMETHODIMP CBasic::put_prpDate(DATE newVal)
1082 m_date = newVal;
1083 return S_OK;
1086 //VT_I4 DECIMAL_NEG //tagVARIANT DISPATCH_PROPERTYPUT
1087 STDMETHODIMP CBasic::inDecimal(DECIMAL val)
1089 m_decimal = val;
1090 return S_OK;
1093 STDMETHODIMP CBasic::outDecimal(DECIMAL* val)
1095 * val = m_decimal;
1096 return S_OK;
1099 STDMETHODIMP CBasic::inoutDecimal(DECIMAL* val)
1101 DECIMAL tmp;
1102 tmp = * val;
1103 * val = m_decimal;
1104 m_decimal = tmp;
1105 return S_OK;
1108 STDMETHODIMP CBasic::get_prpDecimal(DECIMAL* pVal)
1110 * pVal = m_decimal;
1111 return S_OK;
1114 STDMETHODIMP CBasic::put_prpDecimal(DECIMAL newVal)
1116 m_decimal = newVal;
1117 return S_OK;
1120 STDMETHODIMP CBasic::inSCode(SCODE val)
1122 m_scode = val;
1123 return S_OK;
1126 STDMETHODIMP CBasic::outScode(SCODE* val)
1128 * val = m_scode;
1129 return S_OK;
1132 STDMETHODIMP CBasic::inoutSCode(SCODE* val)
1134 SCODE tmp = *val;
1135 * val = m_scode;
1136 m_scode = tmp;
1137 return S_OK;
1140 STDMETHODIMP CBasic::get_prpSCode(SCODE* pVal)
1142 * pVal = m_scode;
1143 return S_OK;
1146 STDMETHODIMP CBasic::put_prpSCode(SCODE newVal)
1148 m_scode = newVal;
1149 return S_OK;
1152 STDMETHODIMP CBasic::inrefLong(LONG* val)
1154 m_long = * val;
1155 return S_OK;
1158 STDMETHODIMP CBasic::inrefVariant(VARIANT* val)
1160 HRESULT hr = S_OK;
1161 if (FAILED(hr = VariantCopy( & m_var1, val)))
1162 return hr;
1163 return S_OK;
1166 STDMETHODIMP CBasic::inrefDecimal(DECIMAL* val)
1168 m_decimal = * val;
1169 return S_OK;
1172 STDMETHODIMP CBasic::get_prpRefLong(long* pVal)
1174 *pVal = m_long;
1175 return S_OK;
1178 STDMETHODIMP CBasic::putref_prpRefLong(long* newVal)
1180 m_long = * newVal;
1181 return S_OK;
1184 STDMETHODIMP CBasic::get_prprefVariant(VARIANT* pVal)
1186 HRESULT hr = S_OK;
1187 hr = VariantCopy(pVal, & m_var1);
1188 return hr;
1191 STDMETHODIMP CBasic::putref_prprefVariant(VARIANT* newVal)
1193 m_var1 = * newVal;
1194 return S_OK;
1197 STDMETHODIMP CBasic::get_prprefDecimal(DECIMAL* pVal)
1199 * pVal = m_decimal;
1200 return S_OK;
1203 STDMETHODIMP CBasic::putref_prprefDecimal(DECIMAL* newVal)
1205 m_decimal = *newVal;
1206 return S_OK;
1210 STDMETHODIMP CBasic::optional6(VARIANT* val1, VARIANT* val2, VARIANT* val3, VARIANT* val4)
1212 HRESULT hr = S_OK;
1213 if (FAILED(hr = m_var1.Copy(val1)))
1214 return hr;
1215 if (FAILED(hr = m_var2.Copy(val2)))
1216 return hr;
1217 if (FAILED(hr = m_var3.Copy(val3)))
1218 return hr;
1219 if (FAILED(hr = m_var4.Copy(val4)))
1220 return hr;
1221 return S_OK;
1224 STDMETHODIMP CBasic::optional7(VARIANT* val1, VARIANT* val2, VARIANT* val3, VARIANT* val4)
1226 HRESULT hr = S_OK;
1227 if (FAILED(hr = VariantCopy(val1, & m_var1)))
1228 return hr;
1229 if (FAILED(hr = VariantCopy(val2, & m_var2)))
1230 return hr;
1231 if (FAILED(hr = VariantCopy(val3, & m_var3)))
1232 return hr;
1233 if (FAILED(hr = VariantCopy(val4, & m_var4)))
1234 return hr;
1236 return S_OK;
1239 STDMETHODIMP CBasic::get_prpMultiArg1(VARIANT* val1, VARIANT* val2, VARIANT* pVal)
1241 HRESULT hr = S_OK;
1242 CComVariant tmp1(*val1);
1243 CComVariant tmp2(*val2);
1245 if (FAILED(hr = VariantCopy(val1, & m_var1)))
1246 return hr;
1247 if (FAILED(hr = VariantCopy(val2, & m_var2)))
1248 return hr;
1249 m_var1 = tmp1;
1250 m_var2 = tmp2;
1251 if (FAILED(hr = VariantCopy(pVal, & m_var3)))
1252 return hr;
1253 return S_OK;
1256 STDMETHODIMP CBasic::put_prpMultiArg1(VARIANT* val1, VARIANT* val2, VARIANT* newVal)
1258 HRESULT hr = S_OK;
1259 CComVariant tmp1( * val1);
1260 CComVariant tmp2( * val2);
1262 if (FAILED(hr = VariantCopy(val1, & m_var1)))
1263 return hr;
1264 if (FAILED(hr = VariantCopy(val2, & m_var2)))
1265 return hr;
1266 m_var1 = tmp1;
1267 m_var2 = tmp2;
1269 m_var3 = *newVal;
1270 return S_OK;
1273 // tagVARIANT DISPATCH_PROPERTYPUT DISPID_PROPERTYPUT VARIANTARG LOCALE_USER_DEFAULT
1275 STDMETHODIMP CBasic::get_prpMultiArg2(VARIANT val1, VARIANT* pVal)
1277 HRESULT hr = S_OK;
1278 m_var1 = val1;
1280 if (FAILED(hr = VariantCopy(pVal, & m_var2)))
1281 return hr;
1282 return S_OK;
1285 STDMETHODIMP CBasic::put_prpMultiArg2(VARIANT val1, VARIANT newVal)
1287 m_var1 = val1;
1288 m_var2 = newVal;
1289 return S_OK;
1292 // returns the values set by prpMultiArg2
1293 STDMETHODIMP CBasic::prpMultiArg2GetValues(VARIANT* val1, VARIANT* valProperty)
1295 HRESULT hr = S_OK;
1296 if (FAILED(VariantCopy(val1, & m_var1)))
1297 return hr;
1298 if (FAILED(VariantCopy(valProperty, & m_var2)))
1299 return hr;
1300 return S_OK;
1303 STDMETHODIMP CBasic::get_prpMultiArg3(LONG* val1, LONG* pVal)
1305 long aLong = *val1;
1306 *val1 = m_long;
1307 m_long = aLong;
1309 * pVal = m_long2;
1310 return S_OK;
1313 STDMETHODIMP CBasic::put_prpMultiArg3(LONG* val1, LONG newVal)
1315 long aLong = *val1;
1316 *val1 = m_long;
1317 m_long = aLong;
1319 m_long2 = newVal;
1320 return S_OK;
1323 STDMETHODIMP CBasic::inUnknown(IUnknown* val)
1325 m_unknown = val;
1327 return S_OK;
1330 STDMETHODIMP CBasic::outUnknown(IUnknown** val)
1332 m_unknown.CopyTo(val);
1333 return S_OK;
1336 STDMETHODIMP CBasic::inoutUnknown(IUnknown** val)
1338 CComPtr<IUnknown> tmp = *val;
1339 m_unknown.CopyTo(val);
1340 m_unknown = tmp;
1341 return S_OK;
1344 STDMETHODIMP CBasic::get_prpUnknown(IUnknown** pVal)
1346 m_prpUnknown.CopyTo(pVal);
1347 return S_OK;
1350 STDMETHODIMP CBasic::put_prpUnknown(IUnknown* newVal)
1352 m_prpUnknown = newVal;
1353 return S_OK;
1356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */