merge the formfield patch from ooo-build
[ooovba.git] / extensions / test / ole / AxTestComponents / Basic.cpp
blob7df0453fc5dfb975cdb38ec3091692f3f70d43cf
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: Basic.cpp,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
30 #include "stdafx.h"
31 //#include "AxTestComponents.h"
32 #include "Basic.h"
36 /////////////////////////////////////////////////////////////////////////////
37 // CBasic
38 CBasic::CBasic(): m_cPrpByte(0),m_nPrpShort(0),m_lPrpLong(0),m_fPrpFloat(0), m_dPrpDouble(0),m_PrpArray(0),
39 m_safearray(NULL), m_bool(VARIANT_FALSE),
40 m_arByte(0), m_arShort(0), m_arLong(0), m_arString(0), m_arVariant(0), m_arFloat(0),
41 m_arDouble(0), m_arObject(0), m_arByteDim2(0), m_date(0.), m_scode(0)
44 memset(&m_cy, 0, sizeof(CY));
45 memset(&m_decimal, 0, sizeof(DECIMAL));
48 CBasic::~CBasic()
50 SafeArrayDestroy(m_safearray);
51 SafeArrayDestroy(m_arByte);
52 SafeArrayDestroy(m_arShort);
53 SafeArrayDestroy(m_arLong);
54 SafeArrayDestroy(m_arString);
55 SafeArrayDestroy(m_arVariant);
56 SafeArrayDestroy(m_arFloat);
57 SafeArrayDestroy(m_arDouble);
58 SafeArrayDestroy(m_arObject);
59 SafeArrayDestroy(m_arByteDim2);
62 STDMETHODIMP CBasic::inBool(VARIANT_BOOL val)
64 m_bool = val;
65 return S_OK;
67 STDMETHODIMP CBasic::inByte(unsigned char val)
69 m_byte = val;
70 return S_OK;
73 STDMETHODIMP CBasic::inShort(short val)
75 m_short = val;
76 return S_OK;
79 STDMETHODIMP CBasic::inLong(long val)
81 m_long = val;
82 return S_OK;
85 STDMETHODIMP CBasic::inString(BSTR val)
87 m_bstr = val;
88 return S_OK;
91 STDMETHODIMP CBasic::inFloat(float val)
93 m_float = val;
94 return S_OK;
97 STDMETHODIMP CBasic::inDouble(double val)
99 m_double = val;
101 CComVariant varDest;
102 CComVariant varSource(val);
103 HRESULT hr = VariantChangeType(&varDest, &varSource, 0, VT_BSTR);
104 return S_OK;
107 STDMETHODIMP CBasic::inVariant(VARIANT val)
109 m_var1 = val;
110 return S_OK;
113 STDMETHODIMP CBasic::inArray(LPSAFEARRAY val)
115 HRESULT hr = S_OK;
116 if (FAILED(hr = SafeArrayDestroy(m_safearray)))
117 return hr;
118 if (FAILED(hr = SafeArrayCopy(val, &m_safearray)))
119 return hr;
120 return S_OK;
123 STDMETHODIMP CBasic::inObject(IDispatch *val)
125 m_obj = val;
126 return S_OK;
129 STDMETHODIMP CBasic::inoutBool(VARIANT_BOOL* val)
131 VARIANT_BOOL aBool = *val;
132 *val = m_bool;
133 m_bool = aBool;
134 return S_OK;
138 STDMETHODIMP CBasic::inoutByte(unsigned char* val)
140 unsigned char aByte = *val;
141 *val = m_byte;
142 m_byte = aByte;
143 return S_OK;
146 STDMETHODIMP CBasic::inoutShort(short *val)
148 short aShort = *val;
149 *val = m_short;
150 m_short = aShort;
151 return S_OK;
154 STDMETHODIMP CBasic::inoutLong(long *val)
156 long aLong = *val;
157 *val = m_long;
158 m_long = aLong;
159 return S_OK;
162 STDMETHODIMP CBasic::inoutString(BSTR *val)
164 CComBSTR aStr = *val;
165 HRESULT hr = S_OK;
166 if (FAILED( hr = m_bstr.CopyTo(val)))
167 return hr;
168 m_bstr = aStr;
169 return S_OK;
172 STDMETHODIMP CBasic::inoutFloat(float *val)
174 float aFloat = *val;
175 *val = m_float;
176 m_float = aFloat;
177 return S_OK;
180 STDMETHODIMP CBasic::inoutDouble(double *val)
182 double aDouble = *val;
183 *val = m_double;
184 m_double = aDouble;
185 return S_OK;
188 STDMETHODIMP CBasic::inoutVariant(VARIANT *val)
190 CComVariant aVar = *val;
191 HRESULT hr = S_OK;
192 if (FAILED(hr = VariantCopy(val, &m_var1)))
193 return hr;
194 m_var1 = aVar;
195 return S_OK;
198 /* The array contains VARIANT according to IDL.
199 If the VARIANTs contain strings then we append "out" to each string.
201 STDMETHODIMP CBasic::inoutArray(LPSAFEARRAY *val)
203 SAFEARRAY* aAr = NULL;
204 HRESULT hr = S_OK;
205 if (FAILED(hr = SafeArrayCopy(*val, &aAr)))
206 return hr;
207 if (FAILED(hr = SafeArrayCopy(m_safearray, val)))
208 return hr;
209 if (FAILED(hr = SafeArrayCopy(aAr, & m_safearray)))
210 return hr;
211 return S_OK;
214 STDMETHODIMP CBasic::inoutObject(IDispatch **val)
216 CComPtr<IDispatch> disp = *val;
217 if (*val)
218 (*val)->Release();
219 *val = m_obj;
220 if (*val)
221 (*val)->AddRef();
222 m_obj = disp;
223 return S_OK;
227 STDMETHODIMP CBasic::outBool(VARIANT_BOOL* val)
229 *val = m_bool;
230 return S_OK;
233 STDMETHODIMP CBasic::outByte(unsigned char *val)
235 *val= m_byte;
236 return S_OK;
239 STDMETHODIMP CBasic::outShort(short *val)
241 *val= m_short;
242 return S_OK;
245 STDMETHODIMP CBasic::outLong(long *val)
247 *val= m_long;
248 return S_OK;
251 STDMETHODIMP CBasic::outString(BSTR *val)
253 *val= SysAllocString(m_bstr);
254 return S_OK;
257 STDMETHODIMP CBasic::outFloat(float *val)
259 *val= m_float;
260 return S_OK;
263 STDMETHODIMP CBasic::outDouble(double *val)
265 *val= m_double;
266 return S_OK;
269 STDMETHODIMP CBasic::outVariant(VARIANT *val)
271 HRESULT hr = S_OK;
272 if (FAILED(hr = VariantCopy(val, &m_var1)))
273 return hr;
274 return S_OK;
277 STDMETHODIMP CBasic::outArray(LPSAFEARRAY *val)
279 HRESULT hr = S_OK;
280 if (FAILED(hr = SafeArrayCopy(m_safearray, val)))
281 return false;
282 return S_OK;
285 STDMETHODIMP CBasic::outObject(IDispatch* *val)
287 *val = m_obj;
288 if (m_obj)
289 (*val)->AddRef();
291 return S_OK;
295 STDMETHODIMP CBasic::get_prpBool(VARIANT_BOOL* pVal)
297 if (!pVal) return E_POINTER;
298 *pVal = m_bool;
299 return S_OK;
302 STDMETHODIMP CBasic::put_prpBool(VARIANT_BOOL val)
304 m_bool = val;
305 return S_OK;
309 STDMETHODIMP CBasic::get_prpByte(unsigned char *pVal)
311 if( !pVal)
312 return E_POINTER;
313 *pVal= m_cPrpByte;
314 return S_OK;
317 STDMETHODIMP CBasic::put_prpByte(unsigned char newVal)
319 m_cPrpByte= newVal;
320 return S_OK;
323 STDMETHODIMP CBasic::get_prpShort(short *pVal)
325 if( !pVal)
326 return E_POINTER;
327 *pVal= m_nPrpShort;
328 return S_OK;
331 STDMETHODIMP CBasic::put_prpShort(short newVal)
333 m_nPrpShort= newVal;
334 return S_OK;
337 STDMETHODIMP CBasic::get_prpLong(long *pVal)
339 if( !pVal)
340 return E_POINTER;
341 *pVal= m_lPrpLong;
342 return S_OK;
345 STDMETHODIMP CBasic::put_prpLong(long newVal)
347 m_lPrpLong= newVal;
348 return S_OK;
351 STDMETHODIMP CBasic::get_prpString(BSTR *pVal)
353 if( !pVal)
354 return E_POINTER;
355 m_bstrPrpString.CopyTo( pVal );
356 return S_OK;
359 STDMETHODIMP CBasic::put_prpString(BSTR newVal)
361 m_bstrPrpString= newVal;
362 return S_OK;
365 STDMETHODIMP CBasic::get_prpFloat(float *pVal)
367 if( !pVal)
368 return E_POINTER;
369 *pVal= m_fPrpFloat;
370 return S_OK;
373 STDMETHODIMP CBasic::put_prpFloat(float newVal)
375 m_fPrpFloat= newVal;
376 return S_OK;
379 STDMETHODIMP CBasic::get_prpDouble(double *pVal)
381 if( !pVal)
382 return E_POINTER;
383 *pVal= m_dPrpDouble;
384 return S_OK;
387 STDMETHODIMP CBasic::put_prpDouble(double newVal)
389 m_dPrpDouble= newVal;
390 return S_OK;
393 STDMETHODIMP CBasic::get_prpVariant(VARIANT *pVal)
395 if( !pVal)
396 return E_POINTER;
397 HRESULT hr = S_OK;
398 if (FAILED(hr = VariantCopy( pVal, &m_PropVariant)))
399 return hr;
400 return hr;
403 STDMETHODIMP CBasic::put_prpVariant(VARIANT newVal)
405 m_PropVariant= newVal;
406 return S_OK;
409 STDMETHODIMP CBasic::get_prpArray(LPSAFEARRAY *pVal)
411 if( !pVal)
412 return E_POINTER;
413 HRESULT hr = S_OK;
414 if (FAILED(hr = SafeArrayCopy( m_PrpArray, pVal)))
415 return hr;
416 return hr;
419 STDMETHODIMP CBasic::put_prpArray(LPSAFEARRAY newVal)
421 HRESULT hr = S_OK;
422 if (FAILED(hr = SafeArrayDestroy( m_PrpArray)))
423 return hr;
424 if (FAILED(hr = SafeArrayCopy( newVal, &m_PrpArray)))
425 return hr;
426 return hr;
429 STDMETHODIMP CBasic::get_prpObject(IDispatch **pVal)
431 if( !pVal)
432 return E_POINTER;
433 *pVal= m_PrpObject;
434 if( *pVal != NULL)
435 (*pVal)->AddRef();
436 return S_OK;
439 STDMETHODIMP CBasic::put_prpObject(IDispatch *newVal)
441 m_PrpObject= newVal;
442 return S_OK;
445 STDMETHODIMP CBasic::mixed1(
446 /* [out][in] */ unsigned char *aChar,
447 /* [out][in] */ float *aFloat,
448 /* [out][in] */ VARIANT *aVar)
451 HRESULT hr= S_OK;
452 inoutByte(aChar);
453 inoutFloat(aFloat);
454 inoutVariant(aVar);
455 return hr;
461 // VT_UI1
463 STDMETHODIMP CBasic::inSequenceLong(LPSAFEARRAY val)
465 HRESULT hr = S_OK;
466 if (FAILED(hr = SafeArrayDestroy(m_arLong)))
467 return hr;
468 if (FAILED(hr = SafeArrayCopy(val, & m_arLong)))
469 return hr;
470 return hr;
473 STDMETHODIMP CBasic::inSequenceByte( LPSAFEARRAY val)
475 HRESULT hr = S_OK;
476 if (FAILED(hr = SafeArrayDestroy(m_arByte)))
477 return hr;
478 if (FAILED(hr = SafeArrayCopy(val, & m_arByte)))
479 return hr;
480 return hr;
483 STDMETHODIMP CBasic::inSequenceShort(LPSAFEARRAY val)
485 HRESULT hr = S_OK;
486 if (FAILED(hr = SafeArrayDestroy(m_arShort)))
487 return hr;
488 if (FAILED(hr = SafeArrayCopy(val, & m_arShort)))
489 return hr;
490 return hr;
493 STDMETHODIMP CBasic::inSequenceString(LPSAFEARRAY val)
495 HRESULT hr = S_OK;
496 if (FAILED(hr = SafeArrayDestroy(m_arString)))
497 return hr;
498 if (FAILED(hr = SafeArrayCopy(val, & m_arString)))
499 return hr;
500 return hr;
503 STDMETHODIMP CBasic::inSequenceFloat(LPSAFEARRAY val)
505 HRESULT hr = S_OK;
506 if (FAILED(hr = SafeArrayDestroy(m_arFloat)))
507 return hr;
508 if (FAILED(hr = SafeArrayCopy(val, & m_arFloat)))
509 return hr;
510 return hr;
513 STDMETHODIMP CBasic::inSequenceDouble(LPSAFEARRAY val)
515 HRESULT hr = S_OK;
516 if (FAILED(hr = SafeArrayDestroy(m_arDouble)))
517 return hr;
518 if (FAILED(hr = SafeArrayCopy(val, & m_arDouble)))
519 return hr;
520 return hr;
523 STDMETHODIMP CBasic::inSequenceObject(LPSAFEARRAY val)
525 HRESULT hr = S_OK;
526 if (FAILED(hr = SafeArrayDestroy(m_arObject)))
527 return hr;
528 if (FAILED(hr = SafeArrayCopy(val, & m_arObject)))
529 return hr;
530 return hr;
533 void CBasic::printArray( LPSAFEARRAY val, BSTR message, VARTYPE type)
536 HRESULT hr= S_OK;
537 USES_CONVERSION;
538 long lbound=0;
539 long ubound= 0;
540 hr= SafeArrayGetLBound( val, 1, &lbound);
541 hr= SafeArrayGetUBound( val, 1, &ubound);
542 long length= ubound - lbound +1;
544 CComVariant varElement;
545 char buf[1024];
546 sprintf( buf,"%s", W2A(message));
548 for( long i= 0; i < length ; i++)
550 char tmp[1024];
551 long data=0;
552 CComVariant var;
553 switch( type)
555 case VT_UI1:
556 case VT_I2:
557 case VT_I4:
558 case VT_ERROR:
559 hr= SafeArrayGetElement( val, &i, (void*)&data);
560 sprintf( tmp, "%d \n", *(long*)&data);
561 break;
562 case VT_BSTR:
563 hr= SafeArrayGetElement( val, &i, (void*)&data);
564 sprintf( tmp, "%S \n", (BSTR)data);
565 break;
566 case VT_VARIANT:
567 hr= SafeArrayGetElement( val, &i, &var);
568 sprintf( tmp, "%x \n", var.byref);
569 break;
570 case VT_R4:
571 hr= SafeArrayGetElement( val, &i, (void*)&data);
572 sprintf( tmp, "%f \n", *(float*) &data);
573 break;
574 case VT_R8: ;
575 hr= SafeArrayGetElement( val, &i, (void*)&data);
576 sprintf( tmp, "%f \n", *(double*) &data);
577 break;
578 case VT_DISPATCH:
579 // we assume the objects are instances of this component and have the
580 // property prpString set.
581 hr= SafeArrayGetElement( val, &i, (void*)&data);
582 IDispatch* pdisp= ( IDispatch*) data;
583 CComDispatchDriver driver( pdisp);
584 CComVariant var;
585 if( pdisp)
587 driver.GetPropertyByName(L"prpString", &var);
588 sprintf( tmp, "%x : %S \n", *(long*)&data, var.bstrVal);
590 else
591 sprintf( tmp, "%x\n", *(long*)&data);
594 strcat( buf, tmp);
596 MessageBox( NULL, _T(A2T(buf)), _T("AxTestComponents.Basic"), MB_OK);
599 // V_ERROR OLECHAR VARIANT VT_UI1
601 STDMETHODIMP CBasic::outSequenceByte(LPSAFEARRAY* val)
603 HRESULT hr= S_OK;
604 hr = SafeArrayCopy(m_arByte, val);
605 return hr;
608 STDMETHODIMP CBasic::outSequenceShort(LPSAFEARRAY* val)
610 HRESULT hr= S_OK;
611 hr = SafeArrayCopy(m_arShort, val);
612 return hr;
615 STDMETHODIMP CBasic::outSequenceLong(LPSAFEARRAY* val)
617 HRESULT hr= S_OK;
618 hr = SafeArrayCopy(m_arLong, val);
619 return hr;
622 STDMETHODIMP CBasic::outSequenceString(LPSAFEARRAY* val)
624 HRESULT hr= S_OK;
625 hr = SafeArrayCopy(m_arString, val);
626 return hr;
629 STDMETHODIMP CBasic::outSequenceFloat(LPSAFEARRAY* val)
631 HRESULT hr= S_OK;
632 hr = SafeArrayCopy(m_arFloat, val);
633 return hr;
636 STDMETHODIMP CBasic::outSequenceDouble(LPSAFEARRAY* val)
638 HRESULT hr= S_OK;
639 hr = SafeArrayCopy(m_arDouble, val);
640 return hr;
643 STDMETHODIMP CBasic::outSequenceObject(LPSAFEARRAY* val)
645 HRESULT hr = S_OK;
646 hr = SafeArrayCopy(m_arObject, val);
647 return S_OK;
650 STDMETHODIMP CBasic::inoutSequenceByte(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_arByte, val)))
657 return hr;
658 m_arByte = arTemp;
659 return hr;
662 STDMETHODIMP CBasic::inoutSequenceShort(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_arShort, val)))
669 return hr;
670 m_arShort = arTemp;
671 return hr;
674 STDMETHODIMP CBasic::inoutSequenceLong(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_arLong, val)))
681 return hr;
682 m_arLong = arTemp;
683 return hr;
686 STDMETHODIMP CBasic::inoutSequenceString(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_arString, val)))
693 return hr;
694 m_arString = arTemp;
695 return hr;
698 STDMETHODIMP CBasic::inoutSequenceFloat(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_arFloat, val)))
705 return hr;
706 m_arFloat = arTemp;
707 return hr;
710 STDMETHODIMP CBasic::inoutSequenceDouble(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_arDouble, val)))
717 return hr;
718 m_arDouble = arTemp;
719 return hr;
722 STDMETHODIMP CBasic::inoutSequenceObject(LPSAFEARRAY* val)
724 HRESULT hr = S_OK;
725 SAFEARRAY *arTemp = NULL;
726 if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
727 return hr;
728 if (FAILED(hr = SafeArrayCopy(m_arObject, val)))
729 return hr;
730 m_arObject = arTemp;
731 return hr;
734 // 2-dimensional Array
735 STDMETHODIMP CBasic::inMulDimArrayLong(LPSAFEARRAY val)
737 printMulArray( val, VT_I4);
738 return S_OK;
740 // 2-dimensional Array
741 STDMETHODIMP CBasic::inMulDimArrayVariant(LPSAFEARRAY val)
743 printMulArray( val, VT_VARIANT);
744 return S_OK;
746 // 3-dimensional Array
747 STDMETHODIMP CBasic::inMulDimArrayLong2(LPSAFEARRAY val)
749 printMulArray( val, VT_I4);
750 return S_OK;
752 // 3-dimensional Array
753 STDMETHODIMP CBasic::inMulDimArrayVariant2(LPSAFEARRAY val)
755 return S_OK;
759 STDMETHODIMP CBasic::inMulDimArrayByte(LPSAFEARRAY val)
761 HRESULT hr = S_OK;
762 if (FAILED(hr = SafeArrayDestroy(m_arByteDim2)))
763 return hr;
764 if (FAILED(hr = SafeArrayCopy(val, & m_arByteDim2)))
765 return hr;
766 return hr;
768 // 3-dimensionales array
769 STDMETHODIMP CBasic::inMulDimArrayByte2(LPSAFEARRAY val)
772 // TODO: Add your implementation code here
773 //printMulArray( val, VT_UI1);
774 return S_OK;
777 // supports 2 and 3 dimensionals SAFEARRAY with elements of long or VARIANT
778 void CBasic::printMulArray( SAFEARRAY* val, VARTYPE type)
780 HRESULT hr= S_OK;
781 UINT dims= SafeArrayGetDim( val);
782 long lbound1;
783 long ubound1;
784 long lbound2;
785 long ubound2;
786 long lbound3;
787 long ubound3;
788 long length1;
789 long length2;
790 long length3;
792 char buff[4096];
793 buff[0]=0;
795 if( dims == 2)
797 hr= SafeArrayGetLBound( val, 1, &lbound1);
798 hr= SafeArrayGetUBound( val, 1, &ubound1);
799 length1= ubound1 - lbound1 +1;
801 hr= SafeArrayGetLBound( val, 2, &lbound2);
802 hr= SafeArrayGetUBound( val, 2, &ubound2);
803 length2= ubound2 - lbound2 + 1;
804 char tmpBuf[1024];
805 tmpBuf[0]=0;
806 long index[2];
807 for( long i= 0; i< length2; i++)
809 for( long j= 0; j<length1; j++)
811 index[0]= j;
812 index[1]= i;
813 long longVal;
814 CComVariant var;
815 switch( type)
817 case VT_I4:
818 hr= SafeArrayGetElement( val, index, &longVal);
819 sprintf( tmpBuf, "(%d,%d): %d\n", index[1], index[0], longVal);
820 break;
821 case VT_UI1:
822 hr= SafeArrayGetElement( val, index, &longVal);
823 sprintf( tmpBuf, "(%d,%d): %d\n", index[1], index[0], (unsigned char)longVal);
824 break;
825 case VT_VARIANT:
826 hr= SafeArrayGetElement( val, index, &var );
827 sprintf( tmpBuf, "(%d,%d): %d (vartype %d)\n", index[1], index[0], var.byref, var.vt);
828 break;
830 strcat( buff,tmpBuf);
837 else if( dims == 3 )
839 hr= SafeArrayGetLBound( val, 1, &lbound1);
840 hr= SafeArrayGetUBound( val, 1, &ubound1);
841 length1= ubound1 - lbound1 +1;
843 hr= SafeArrayGetLBound( val, 2, &lbound2);
844 hr= SafeArrayGetUBound( val, 2, &ubound2);
845 length2= ubound2 - lbound2 + 1;
847 hr= SafeArrayGetLBound( val, 3, &lbound3);
848 hr= SafeArrayGetUBound( val, 3, &ubound3);
849 length3= ubound3 - lbound3 +1;
850 char tmpBuf[1024];
851 tmpBuf[0]=0;
852 long index[3];
853 for( long i= 0; i< length3; i++)
855 for( long j= 0; j<length2; j++)
857 for( long k= 0; k<length1; k++)
859 index[0]= k;
860 index[1]= j;
861 index[2]= i;
862 long longVal;
863 CComVariant var;
864 switch( type)
866 case VT_I4:
867 hr= SafeArrayGetElement( val, index, &longVal);
868 sprintf( tmpBuf, "(%d,%d,%d): %d\n", index[2], index[1], index[0], longVal);
869 break;
870 case VT_UI1:
871 hr= SafeArrayGetElement( val, index, &longVal);
872 sprintf( tmpBuf, "(%d,%d,%d): %d\n", index[2], index[1], index[0], (unsigned char)longVal);
873 break;
875 case VT_VARIANT:
876 hr= SafeArrayGetElement( val, index, &var );
877 sprintf( tmpBuf, "(%d,%d,%d): %d (vartype %d)\n", index[2], index[1], index[0], var.byref, var.vt);
878 break;
880 strcat( buff,tmpBuf);
888 MessageBox( NULL, A2T( buff), _T("AxTestControl.Basic"), MB_OK);
896 STDMETHODIMP CBasic::outMore(long* val1, long* val2)
898 // TODO: Add your implementation code here
899 *val1= 111;
900 *val2= 112;
901 return S_OK;
903 // If an optional parameter was not provided then the respective member will
904 // not be set
905 STDMETHODIMP CBasic::optional1(/*[in]*/ long val1, /*[in, optional]*/ VARIANT* val2)
907 m_long = val1;
908 if (val2->vt != VT_ERROR)
909 m_var1 = *val2;
910 return S_OK;
913 STDMETHODIMP CBasic::optional2(/*[out]*/ long* val1,/*[out, optional]*/ VARIANT* val2)
915 HRESULT hr = S_OK;
916 *val1 = m_long;
918 if (val2->vt != VT_ERROR)
919 hr = VariantCopy(val2, & m_var1);
920 return hr;
923 STDMETHODIMP CBasic::optional3(/*[in, optional]*/ VARIANT* val1,/*[in, optional]*/ VARIANT* val2)
925 //if (val1->vt != VT_ERROR)
926 m_var1 = *val1;
928 //if (val2->vt != VT_ERROR)
929 m_var2 = *val2;
930 return S_OK;
933 STDMETHODIMP CBasic::optional4(/*[in, out, optional]*/ VARIANT* val1,
934 /*[in, out, optional]*/ VARIANT* val2)
936 HRESULT hr = S_OK;
937 //return the previously set in values
938 if (val1->vt != VT_ERROR)
940 CComVariant var1(*val1);
941 if (FAILED(hr = VariantCopy(val1, & m_var1)))
942 return hr;
943 m_var1 = var1;
945 if (val2->vt != VT_ERROR)
947 CComVariant var2(*val2);
948 if (FAILED(hr = VariantCopy(val2, & m_var2)))
949 return hr;
950 m_var2 = var2;
952 return hr;
955 STDMETHODIMP CBasic::optional5(/*[out, optional]*/ VARIANT* val1,
956 /*[out, optional]*/ VARIANT* val2)
958 HRESULT hr = S_OK;
959 if (FAILED(hr = VariantCopy(val1, &m_var1)))
960 return hr;
961 if (FAILED(hr = VariantCopy(val2, &m_var2)))
962 return hr;
963 return hr;
966 STDMETHODIMP CBasic::defaultvalue1(/*[in, defaultvalue(10)]*/ long val1,
967 /*[in, defaultvalue(3.14)]*/ double* val2,
968 // /*[in, defaultvalue(10)]*/ VARIANT val3,
969 /*[in, defaultvalue(100)]*/ VARIANT* val4)
971 m_long = val1;
972 m_double = *val2;
973 // m_var1 = val3;
974 m_var2 = *val4;
975 return S_OK;
977 STDMETHODIMP CBasic::defaultvalue2(/*[in, out, defaultvalue(10)]*/ long* val1,
978 /*[in, out, defaultvalue(3.14)]*/ double* val2,
979 // /*[in, out, defaultvalue(10)]*/ VARIANT* val3,
980 /*[in, out, defaultvalue(100)]*/ VARIANT* val4)
982 HRESULT hr = S_OK;
983 long aLong = *val1;
984 double aDouble = *val2;
985 // CComVariant var1(*val3);
986 CComVariant var2(*val4);
987 *val1 = m_long;
988 *val2 = m_double;
989 //if (FAILED(hr = VariantCopy(val3, &m_var1)))
990 // return hr;
991 if (FAILED(hr = VariantCopy(val4, &m_var2)))
992 return hr;
993 m_long = aLong;
994 m_double = aDouble;
995 // m_var1 = var1;
996 m_var2 = var2;
997 return hr;
999 /* val2 contains the variable argument list. If no such arguments are supplied
1000 then the safearray is invalid. SafeArrayCopy then returns E_INVALIDARG
1002 STDMETHODIMP CBasic::varargfunc1(/*[in]*/ long val1,/*[in]*/ LPSAFEARRAY val2)
1004 m_long = val1;
1006 HRESULT hr = S_OK;
1007 if (FAILED(hr = SafeArrayDestroy(m_safearray)))
1008 return hr;
1009 if (FAILED(hr = SafeArrayCopy(val2, & m_safearray)))
1011 if (hr != E_INVALIDARG)
1012 return hr;
1014 return S_OK;
1017 STDMETHODIMP CBasic::varargfunc2(/*[out]*/ long* val1, /*[out]*/ SAFEARRAY ** val2)
1019 *val1 = m_long;
1020 HRESULT hr = SafeArrayCopy(m_safearray, val2);
1021 return hr;
1024 STDMETHODIMP CBasic::inSequenceByteDim2(LPSAFEARRAY val)
1026 HRESULT hr = S_OK;
1027 if (FAILED(hr = SafeArrayDestroy(m_arByteDim2)))
1028 return hr;
1029 if (FAILED(hr = SafeArrayCopy(val, & m_arByteDim2)))
1030 return hr;
1031 return hr;
1035 STDMETHODIMP CBasic::inCurrency(CY val)
1037 m_cy = val;
1038 return S_OK;
1041 STDMETHODIMP CBasic::outCurrency(CY* val)
1043 *val = m_cy;
1044 return S_OK;
1047 STDMETHODIMP CBasic::inoutCurrency(CY* val)
1049 CY tmp = *val;
1050 *val = m_cy;
1051 m_cy = tmp;
1052 return S_OK;
1055 STDMETHODIMP CBasic::inDate(DATE val)
1057 m_date = val;
1058 return S_OK;
1061 STDMETHODIMP CBasic::outDate(DATE* val)
1063 *val = m_date;
1064 return S_OK;
1067 STDMETHODIMP CBasic::inoutDate(DATE* val)
1069 DATE tmp = *val;
1070 *val = m_date;
1071 m_date = tmp;
1072 return S_OK;
1075 STDMETHODIMP CBasic::get_prpCurrency(CY* pVal)
1077 *pVal = m_cy;
1078 return S_OK;
1081 STDMETHODIMP CBasic::put_prpCurrency(CY newVal)
1083 m_cy = newVal;
1084 return S_OK;
1087 STDMETHODIMP CBasic::get_prpDate(DATE* pVal)
1089 *pVal = m_date;
1090 return S_OK;
1093 STDMETHODIMP CBasic::put_prpDate(DATE newVal)
1095 m_date = newVal;
1096 return S_OK;
1099 //VT_I4 DECIMAL_NEG //tagVARIANT DISPATCH_PROPERTYPUT
1100 STDMETHODIMP CBasic::inDecimal(DECIMAL val)
1102 m_decimal = val;
1103 return S_OK;
1106 STDMETHODIMP CBasic::outDecimal(DECIMAL* val)
1108 * val = m_decimal;
1109 return S_OK;
1112 STDMETHODIMP CBasic::inoutDecimal(DECIMAL* val)
1114 DECIMAL tmp;
1115 tmp = * val;
1116 * val = m_decimal;
1117 m_decimal = tmp;
1118 return S_OK;
1121 STDMETHODIMP CBasic::get_prpDecimal(DECIMAL* pVal)
1123 * pVal = m_decimal;
1124 return S_OK;
1127 STDMETHODIMP CBasic::put_prpDecimal(DECIMAL newVal)
1129 m_decimal = newVal;
1130 return S_OK;
1133 STDMETHODIMP CBasic::inSCode(SCODE val)
1135 m_scode = val;
1136 return S_OK;
1139 STDMETHODIMP CBasic::outScode(SCODE* val)
1141 * val = m_scode;
1142 return S_OK;
1145 STDMETHODIMP CBasic::inoutSCode(SCODE* val)
1147 SCODE tmp = *val;
1148 * val = m_scode;
1149 m_scode = tmp;
1150 return S_OK;
1153 STDMETHODIMP CBasic::get_prpSCode(SCODE* pVal)
1155 * pVal = m_scode;
1156 return S_OK;
1159 STDMETHODIMP CBasic::put_prpSCode(SCODE newVal)
1161 m_scode = newVal;
1162 return S_OK;
1165 STDMETHODIMP CBasic::inrefLong(LONG* val)
1167 m_long = * val;
1168 return S_OK;
1171 STDMETHODIMP CBasic::inrefVariant(VARIANT* val)
1173 HRESULT hr = S_OK;
1174 if (FAILED(hr = VariantCopy( & m_var1, val)))
1175 return hr;
1176 return S_OK;
1179 STDMETHODIMP CBasic::inrefDecimal(DECIMAL* val)
1181 m_decimal = * val;
1182 return S_OK;
1185 STDMETHODIMP CBasic::get_prpRefLong(long* pVal)
1187 *pVal = m_long;
1188 return S_OK;
1191 STDMETHODIMP CBasic::putref_prpRefLong(long* newVal)
1193 m_long = * newVal;
1194 return S_OK;
1197 STDMETHODIMP CBasic::get_prprefVariant(VARIANT* pVal)
1199 HRESULT hr = S_OK;
1200 hr = VariantCopy(pVal, & m_var1);
1201 return hr;
1204 STDMETHODIMP CBasic::putref_prprefVariant(VARIANT* newVal)
1206 m_var1 = * newVal;
1207 return S_OK;
1210 STDMETHODIMP CBasic::get_prprefDecimal(DECIMAL* pVal)
1212 * pVal = m_decimal;
1213 return S_OK;
1216 STDMETHODIMP CBasic::putref_prprefDecimal(DECIMAL* newVal)
1218 m_decimal = *newVal;
1219 return S_OK;
1223 STDMETHODIMP CBasic::optional6(VARIANT* val1, VARIANT* val2, VARIANT* val3, VARIANT* val4)
1225 HRESULT hr = S_OK;
1226 if (FAILED(hr = m_var1.Copy(val1)))
1227 return hr;
1228 if (FAILED(hr = m_var2.Copy(val2)))
1229 return hr;
1230 if (FAILED(hr = m_var3.Copy(val3)))
1231 return hr;
1232 if (FAILED(hr = m_var4.Copy(val4)))
1233 return hr;
1234 return S_OK;
1237 STDMETHODIMP CBasic::optional7(VARIANT* val1, VARIANT* val2, VARIANT* val3, VARIANT* val4)
1239 HRESULT hr = S_OK;
1240 if (FAILED(hr = VariantCopy(val1, & m_var1)))
1241 return hr;
1242 if (FAILED(hr = VariantCopy(val2, & m_var2)))
1243 return hr;
1244 if (FAILED(hr = VariantCopy(val3, & m_var3)))
1245 return hr;
1246 if (FAILED(hr = VariantCopy(val4, & m_var4)))
1247 return hr;
1249 return S_OK;
1252 STDMETHODIMP CBasic::get_prpMultiArg1(VARIANT* val1, VARIANT* val2, VARIANT* pVal)
1254 HRESULT hr = S_OK;
1255 CComVariant tmp1(*val1);
1256 CComVariant tmp2(*val2);
1258 if (FAILED(hr = VariantCopy(val1, & m_var1)))
1259 return hr;
1260 if (FAILED(hr = VariantCopy(val2, & m_var2)))
1261 return hr;
1262 m_var1 = tmp1;
1263 m_var2 = tmp2;
1264 if (FAILED(hr = VariantCopy(pVal, & m_var3)))
1265 return hr;
1266 return S_OK;
1269 STDMETHODIMP CBasic::put_prpMultiArg1(VARIANT* val1, VARIANT* val2, VARIANT* newVal)
1271 HRESULT hr = S_OK;
1272 CComVariant tmp1( * val1);
1273 CComVariant tmp2( * val2);
1275 if (FAILED(hr = VariantCopy(val1, & m_var1)))
1276 return hr;
1277 if (FAILED(hr = VariantCopy(val2, & m_var2)))
1278 return hr;
1279 m_var1 = tmp1;
1280 m_var2 = tmp2;
1282 m_var3 = *newVal;
1283 return S_OK;
1286 // tagVARIANT DISPATCH_PROPERTYPUT DISPID_PROPERTYPUT VARIANTARG LOCALE_USER_DEFAULT
1288 STDMETHODIMP CBasic::get_prpMultiArg2(VARIANT val1, VARIANT* pVal)
1290 HRESULT hr = S_OK;
1291 m_var1 = val1;
1293 if (FAILED(hr = VariantCopy(pVal, & m_var2)))
1294 return hr;
1295 return S_OK;
1298 STDMETHODIMP CBasic::put_prpMultiArg2(VARIANT val1, VARIANT newVal)
1300 m_var1 = val1;
1301 m_var2 = newVal;
1302 return S_OK;
1305 // returns the values set by prpMultiArg2
1306 STDMETHODIMP CBasic::prpMultiArg2GetValues(VARIANT* val1, VARIANT* valProperty)
1308 HRESULT hr = S_OK;
1309 if (FAILED(VariantCopy(val1, & m_var1)))
1310 return hr;
1311 if (FAILED(VariantCopy(valProperty, & m_var2)))
1312 return hr;
1313 return S_OK;
1316 STDMETHODIMP CBasic::get_prpMultiArg3(LONG* val1, LONG* pVal)
1318 long aLong = *val1;
1319 *val1 = m_long;
1320 m_long = aLong;
1322 * pVal = m_long2;
1323 return S_OK;
1326 STDMETHODIMP CBasic::put_prpMultiArg3(LONG* val1, LONG newVal)
1328 long aLong = *val1;
1329 *val1 = m_long;
1330 m_long = aLong;
1332 m_long2 = newVal;
1333 return S_OK;
1336 STDMETHODIMP CBasic::inUnknown(IUnknown* val)
1338 m_unknown = val;
1340 return S_OK;
1343 STDMETHODIMP CBasic::outUnknown(IUnknown** val)
1345 m_unknown.CopyTo(val);
1346 return S_OK;
1349 STDMETHODIMP CBasic::inoutUnknown(IUnknown** val)
1351 CComPtr<IUnknown> tmp = *val;
1352 m_unknown.CopyTo(val);
1353 m_unknown = tmp;
1354 return S_OK;
1357 STDMETHODIMP CBasic::get_prpUnknown(IUnknown** pVal)
1359 m_prpUnknown.CopyTo(pVal);
1360 return S_OK;
1363 STDMETHODIMP CBasic::put_prpUnknown(IUnknown* newVal)
1365 m_prpUnknown = newVal;
1366 return S_OK;