summaryrefslogtreecommitdiffstats
path: root/extensions/test/ole/AxTestComponents/Basic.cpp
blob: 8aad56e8af52d664aed2e931255dcb6008f4e9ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "stdafx.h"
#include "Basic.h"



// CBasic
CBasic::CBasic():   m_cPrpByte(0),m_nPrpShort(0),m_lPrpLong(0),m_fPrpFloat(0), m_dPrpDouble(0),m_PrpArray(0),
m_safearray(NULL), m_bool(VARIANT_FALSE),
m_arByte(0), m_arShort(0), m_arLong(0), m_arString(0), m_arVariant(0), m_arFloat(0),
m_arDouble(0), m_arObject(0), m_arByteDim2(0), m_date(0.), m_scode(0)

{
    memset(&m_cy, 0, sizeof(CY));
    memset(&m_decimal, 0, sizeof(DECIMAL));
}

CBasic::~CBasic()
{
    SafeArrayDestroy(m_safearray);
    SafeArrayDestroy(m_arByte);
    SafeArrayDestroy(m_arShort);
    SafeArrayDestroy(m_arLong);
    SafeArrayDestroy(m_arString);
    SafeArrayDestroy(m_arVariant);
    SafeArrayDestroy(m_arFloat);
    SafeArrayDestroy(m_arDouble);
    SafeArrayDestroy(m_arObject);
    SafeArrayDestroy(m_arByteDim2);

}
STDMETHODIMP CBasic::inBool(VARIANT_BOOL val)
{
    m_bool = val;
    return S_OK;
}
STDMETHODIMP CBasic::inByte(unsigned char val)
{
    m_byte = val;
    return S_OK;
}

STDMETHODIMP CBasic::inShort(short val)
{
    m_short = val;
    return S_OK;
}

STDMETHODIMP CBasic::inLong(long val)
{
    m_long = val;
    return S_OK;
}

STDMETHODIMP CBasic::inString(BSTR val)
{
    m_bstr = val;
    return S_OK;
}

STDMETHODIMP CBasic::inFloat(float val)
{
    m_float = val;
    return S_OK;
}

STDMETHODIMP CBasic::inDouble(double val)
{
    m_double = val;

    CComVariant varDest;
    CComVariant varSource(val);
    HRESULT hr = VariantChangeType(&varDest, &varSource, 0, VT_BSTR);
    return S_OK;
}

STDMETHODIMP CBasic::inVariant(VARIANT val)
{
    m_var1 = val;
    return S_OK;
}

STDMETHODIMP CBasic::inArray(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_safearray)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, &m_safearray)))
        return hr;
    return S_OK;
}

STDMETHODIMP CBasic::inObject(IDispatch *val)
{
    m_obj = val;
    return S_OK;
}

STDMETHODIMP CBasic::inoutBool(VARIANT_BOOL* val)
{
    VARIANT_BOOL aBool = *val;
    *val = m_bool;
    m_bool = aBool;
    return S_OK;
}


STDMETHODIMP CBasic::inoutByte(unsigned char* val)
{
    unsigned char aByte = *val;
    *val = m_byte;
    m_byte = aByte;
    return S_OK;
}

STDMETHODIMP CBasic::inoutShort(short *val)
{
    short aShort = *val;
    *val = m_short;
    m_short = aShort;
    return S_OK;
}

STDMETHODIMP CBasic::inoutLong(long *val)
{
    long aLong = *val;
    *val = m_long;
    m_long = aLong;
    return S_OK;
}

STDMETHODIMP CBasic::inoutString(BSTR *val)
{
    CComBSTR aStr = *val;
    HRESULT hr = S_OK;
    if (FAILED( hr = m_bstr.CopyTo(val)))
        return hr;
    m_bstr = aStr;
    return S_OK;
}

STDMETHODIMP CBasic::inoutFloat(float *val)
{
    float aFloat = *val;
    *val = m_float;
    m_float = aFloat;
    return S_OK;
}

STDMETHODIMP CBasic::inoutDouble(double *val)
{
    double aDouble = *val;
    *val = m_double;
    m_double  = aDouble;
    return S_OK;
}

STDMETHODIMP CBasic::inoutVariant(VARIANT *val)
{
    CComVariant aVar = *val;
    HRESULT hr = S_OK;
    if (FAILED(hr = VariantCopy(val, &m_var1)))
        return hr;
    m_var1 = aVar;
    return S_OK;
}

/* The array contains VARIANT according to IDL.
    If the VARIANTs contain strings then we append "out" to each string.
*/
STDMETHODIMP CBasic::inoutArray(LPSAFEARRAY *val)
{
    SAFEARRAY* aAr = NULL;
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayCopy(*val, &aAr)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(m_safearray, val)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(aAr, & m_safearray)))
        return hr;
    return S_OK;
}

STDMETHODIMP CBasic::inoutObject(IDispatch **val)
{
    CComPtr<IDispatch> disp = *val;
    if (*val)
        (*val)->Release();
    *val = m_obj;
    if (*val)
        (*val)->AddRef();
    m_obj = disp;
    return S_OK;
}


STDMETHODIMP CBasic::outBool(VARIANT_BOOL* val)
{
    *val = m_bool;
    return S_OK;
}

STDMETHODIMP CBasic::outByte(unsigned char *val)
{
    *val= m_byte;
    return S_OK;
}

STDMETHODIMP CBasic::outShort(short *val)
{
    *val= m_short;
    return S_OK;
}

STDMETHODIMP CBasic::outLong(long *val)
{
    *val= m_long;
    return S_OK;
}

STDMETHODIMP CBasic::outString(BSTR *val)
{
    *val= SysAllocString(m_bstr);
    return S_OK;
}

STDMETHODIMP CBasic::outFloat(float *val)
{
    *val= m_float;
    return S_OK;
}

STDMETHODIMP CBasic::outDouble(double *val)
{
    *val= m_double;
    return S_OK;
}

STDMETHODIMP CBasic::outVariant(VARIANT *val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = VariantCopy(val, &m_var1)))
        return hr;
    return S_OK;
}

STDMETHODIMP CBasic::outArray(LPSAFEARRAY *val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayCopy(m_safearray, val)))
        return false;
    return S_OK;
}

STDMETHODIMP CBasic::outObject(IDispatch* *val)
{
    *val = m_obj;
    if (m_obj)
        (*val)->AddRef();

    return S_OK;
}


STDMETHODIMP CBasic::get_prpBool(VARIANT_BOOL* pVal)
{
    if (!pVal) return E_POINTER;
    *pVal = m_bool;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpBool(VARIANT_BOOL val)
{
    m_bool = val;
    return S_OK;
}


STDMETHODIMP CBasic::get_prpByte(unsigned char *pVal)
{
    if( !pVal)
        return E_POINTER;
    *pVal= m_cPrpByte;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpByte(unsigned char newVal)
{
    m_cPrpByte= newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpShort(short *pVal)
{
    if( !pVal)
        return E_POINTER;
    *pVal= m_nPrpShort;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpShort(short newVal)
{
    m_nPrpShort= newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpLong(long *pVal)
{
    if( !pVal)
        return E_POINTER;
    *pVal= m_lPrpLong;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpLong(long newVal)
{
    m_lPrpLong= newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpString(BSTR *pVal)
{
    if( !pVal)
        return E_POINTER;
    m_bstrPrpString.CopyTo( pVal );
    return S_OK;
}

STDMETHODIMP CBasic::put_prpString(BSTR newVal)
{
    m_bstrPrpString= newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpFloat(float *pVal)
{
    if( !pVal)
        return E_POINTER;
    *pVal= m_fPrpFloat;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpFloat(float newVal)
{
    m_fPrpFloat= newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpDouble(double *pVal)
{
    if( !pVal)
        return E_POINTER;
    *pVal= m_dPrpDouble;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpDouble(double newVal)
{
    m_dPrpDouble= newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpVariant(VARIANT *pVal)
{
    if( !pVal)
        return E_POINTER;
    HRESULT hr = S_OK;
    if (FAILED(hr = VariantCopy( pVal, &m_PropVariant)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::put_prpVariant(VARIANT newVal)
{
    m_PropVariant= newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpArray(LPSAFEARRAY *pVal)
{
    if( !pVal)
        return E_POINTER;
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayCopy( m_PrpArray, pVal)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::put_prpArray(LPSAFEARRAY newVal)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy( m_PrpArray)))
        return hr;
    if (FAILED(hr = SafeArrayCopy( newVal, &m_PrpArray)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::get_prpObject(IDispatch **pVal)
{
    if( !pVal)
        return E_POINTER;
    *pVal= m_PrpObject;
    if( *pVal != NULL)
        (*pVal)->AddRef();
    return S_OK;
}

STDMETHODIMP CBasic::put_prpObject(IDispatch *newVal)
{
    m_PrpObject= newVal;
    return S_OK;
}

STDMETHODIMP CBasic::mixed1(
            /* [out][in] */ unsigned char *aChar,
            /* [out][in] */ float *aFloat,
            /* [out][in] */ VARIANT *aVar)

{
    HRESULT hr= S_OK;
    inoutByte(aChar);
    inoutFloat(aFloat);
    inoutVariant(aVar);
    return hr;
}




// VT_UI1

STDMETHODIMP CBasic::inSequenceLong(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arLong)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arLong)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::inSequenceByte( LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arByte)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arByte)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::inSequenceShort(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arShort)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arShort)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::inSequenceString(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arString)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arString)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::inSequenceFloat(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arFloat)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arFloat)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::inSequenceDouble(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arDouble)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arDouble)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::inSequenceObject(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arObject)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arObject)))
        return hr;
    return hr;
}

void CBasic::printArray( LPSAFEARRAY val, BSTR message, VARTYPE type)
{

    HRESULT hr= S_OK;
    USES_CONVERSION;
    long lbound=0;
    long ubound= 0;
    hr= SafeArrayGetLBound( val, 1, &lbound);
    hr= SafeArrayGetUBound( val, 1, &ubound);
    long length= ubound - lbound +1;

    CComVariant varElement;
    char buf[1024];
    sprintf( buf,"%s", W2A(message));

    for( long i= 0; i < length ; i++)
    {
        char tmp[1024];
        long data=0;
        CComVariant var;
        switch( type)
        {
        case VT_UI1:
        case VT_I2:
        case VT_I4:
        case VT_ERROR:
            hr= SafeArrayGetElement( val, &i, (void*)&data);
            sprintf( tmp, "%ld \n", *(long*)&data);
            break;
        case VT_BSTR:
            hr= SafeArrayGetElement( val, &i, (void*)&data);
            sprintf( tmp, "%S \n", (BSTR)data);
            break;
        case VT_VARIANT:
            hr= SafeArrayGetElement( val, &i, &var);
            sprintf( tmp, "%x \n", var.byref);
            break;
        case VT_R4:
            hr= SafeArrayGetElement( val, &i, (void*)&data);
            sprintf( tmp, "%f \n", *(float*) &data);
            break;
        case VT_R8: ;
            hr= SafeArrayGetElement( val, &i, (void*)&data);
            sprintf( tmp, "%f \n", *(double*) &data);
            break;
        case VT_DISPATCH:
            // we assume the objects are instances of this component and have the
            // property prpString set.
            hr= SafeArrayGetElement( val, &i, (void*)&data);
            IDispatch* pdisp= ( IDispatch*) data;
            CComDispatchDriver driver( pdisp);
            CComVariant var;
            if( pdisp)
            {
                driver.GetPropertyByName(L"prpString", &var);
                sprintf( tmp, "%x : %S \n", *(long*)&data, var.bstrVal);
            }
            else
                sprintf( tmp, "%x\n", *(long*)&data);
        }

        strcat( buf, tmp);
    }
    MessageBox( NULL, _T(A2T(buf)), _T("AxTestComponents.Basic"), MB_OK);

}
// V_ERROR OLECHAR VARIANT VT_UI1

STDMETHODIMP CBasic::outSequenceByte(LPSAFEARRAY* val)
{
    HRESULT hr= S_OK;
    hr = SafeArrayCopy(m_arByte, val);
    return hr;
}

STDMETHODIMP CBasic::outSequenceShort(LPSAFEARRAY* val)
{
    HRESULT hr= S_OK;
    hr = SafeArrayCopy(m_arShort, val);
    return hr;
}

STDMETHODIMP CBasic::outSequenceLong(LPSAFEARRAY* val)
{
    HRESULT hr= S_OK;
    hr = SafeArrayCopy(m_arLong, val);
    return hr;
}

STDMETHODIMP CBasic::outSequenceString(LPSAFEARRAY* val)
{
    HRESULT hr= S_OK;
    hr = SafeArrayCopy(m_arString, val);
    return hr;
}

STDMETHODIMP CBasic::outSequenceFloat(LPSAFEARRAY* val)
{
    HRESULT hr= S_OK;
    hr = SafeArrayCopy(m_arFloat, val);
    return hr;
}

STDMETHODIMP CBasic::outSequenceDouble(LPSAFEARRAY* val)
{
    HRESULT hr= S_OK;
    hr = SafeArrayCopy(m_arDouble, val);
    return hr;
}

STDMETHODIMP CBasic::outSequenceObject(LPSAFEARRAY* val)
{
    HRESULT hr = S_OK;
    hr = SafeArrayCopy(m_arObject, val);
    return S_OK;
}

STDMETHODIMP CBasic::inoutSequenceByte(LPSAFEARRAY* val)
{
    HRESULT hr = S_OK;
    SAFEARRAY *arTemp = NULL;
    if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(m_arByte, val)))
        return hr;
    m_arByte = arTemp;
    return hr;
}

STDMETHODIMP CBasic::inoutSequenceShort(LPSAFEARRAY* val)
{
    HRESULT hr = S_OK;
    SAFEARRAY *arTemp = NULL;
    if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(m_arShort, val)))
        return hr;
    m_arShort = arTemp;
    return hr;
}

STDMETHODIMP CBasic::inoutSequenceLong(LPSAFEARRAY* val)
{
    HRESULT hr = S_OK;
    SAFEARRAY *arTemp = NULL;
    if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(m_arLong, val)))
        return hr;
    m_arLong = arTemp;
    return hr;
}

STDMETHODIMP CBasic::inoutSequenceString(LPSAFEARRAY* val)
{
    HRESULT hr = S_OK;
    SAFEARRAY *arTemp = NULL;
    if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(m_arString, val)))
        return hr;
    m_arString = arTemp;
    return hr;
}

STDMETHODIMP CBasic::inoutSequenceFloat(LPSAFEARRAY* val)
{
    HRESULT hr = S_OK;
    SAFEARRAY *arTemp = NULL;
    if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(m_arFloat, val)))
        return hr;
    m_arFloat = arTemp;
    return hr;
}

STDMETHODIMP CBasic::inoutSequenceDouble(LPSAFEARRAY* val)
{
    HRESULT hr = S_OK;
    SAFEARRAY *arTemp = NULL;
    if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(m_arDouble, val)))
        return hr;
    m_arDouble = arTemp;
    return hr;
}

STDMETHODIMP CBasic::inoutSequenceObject(LPSAFEARRAY* val)
{
    HRESULT hr = S_OK;
    SAFEARRAY *arTemp = NULL;
    if (FAILED(hr = SafeArrayCopy(*val, &arTemp)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(m_arObject, val)))
        return hr;
    m_arObject = arTemp;
    return hr;
}

// 2-dimensional Array
STDMETHODIMP CBasic::inMulDimArrayLong(LPSAFEARRAY val)
{
    printMulArray( val, VT_I4);
    return S_OK;
}
// 2-dimensional Array
STDMETHODIMP CBasic::inMulDimArrayVariant(LPSAFEARRAY val)
{
    printMulArray( val, VT_VARIANT);
    return S_OK;
}
// 3-dimensional Array
STDMETHODIMP CBasic::inMulDimArrayLong2(LPSAFEARRAY val)
{
    printMulArray( val, VT_I4);
    return S_OK;
}
// 3-dimensional Array
STDMETHODIMP CBasic::inMulDimArrayVariant2(LPSAFEARRAY val)
{
    return S_OK;
}


STDMETHODIMP CBasic::inMulDimArrayByte(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arByteDim2)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arByteDim2)))
        return hr;
    return hr;
}
// 3-dimensionales array
STDMETHODIMP CBasic::inMulDimArrayByte2(LPSAFEARRAY val)
{

    // TODO: Add your implementation code here
    //printMulArray( val, VT_UI1);
    return S_OK;
}

// supports 2 and 3 dimensional SAFEARRAY with elements of long or VARIANT
void CBasic::printMulArray( SAFEARRAY* val, VARTYPE type)
{
    HRESULT hr= S_OK;
    UINT dims= SafeArrayGetDim( val);
    long lbound1;
    long ubound1;
    long lbound2;
    long ubound2;
    long lbound3;
    long ubound3;
    long length1;
    long length2;

    char buff[4096];
    buff[0]=0;

    if( dims == 2)
    {
        hr= SafeArrayGetLBound( val, 1, &lbound1);
        hr= SafeArrayGetUBound( val, 1, &ubound1);
        length1= ubound1 - lbound1 +1;

        hr= SafeArrayGetLBound( val, 2, &lbound2);
        hr= SafeArrayGetUBound( val, 2, &ubound2);
        length2= ubound2 - lbound2 + 1;
        char tmpBuf[1024];
        tmpBuf[0]=0;
        long index[2];
        for( long i= 0; i< length2; i++)
        {
            for( long j= 0; j<length1; j++)
            {
                index[0]= j;
                index[1]= i;
                long longVal;
                CComVariant var;
                switch( type)
                {
                case VT_I4:
                    hr= SafeArrayGetElement( val, index, &longVal);
                    sprintf( tmpBuf, "(%ld,%ld): %ld\n", index[1], index[0], longVal);
                    break;
                case VT_UI1:
                    hr= SafeArrayGetElement( val, index, &longVal);
                    sprintf( tmpBuf, "(%ld,%ld): %d\n", index[1], index[0], (unsigned char)longVal);
                    break;
                case VT_VARIANT:
                    hr= SafeArrayGetElement( val, index, &var );
                    sprintf( tmpBuf, "(%ld,%ld):  %d (vartype %d)\n",  index[1], index[0], var.byref, var.vt);
                    break;
                }
                strcat( buff,tmpBuf);
            }

        }


    }
    else if( dims == 3 )
    {
        hr= SafeArrayGetLBound( val, 1, &lbound1);
        hr= SafeArrayGetUBound( val, 1, &ubound1);
        length1= ubound1 - lbound1 +1;

        hr= SafeArrayGetLBound( val, 2, &lbound2);
        hr= SafeArrayGetUBound( val, 2, &ubound2);
        length2= ubound2 - lbound2 + 1;

        hr= SafeArrayGetLBound( val, 3, &lbound3);
        hr= SafeArrayGetUBound( val, 3, &ubound3);
        long length3= ubound3 - lbound3 +1;
        char tmpBuf[1024];
        tmpBuf[0]=0;
        long index[3];
        for( long i= 0; i< length3; i++)
        {
            for( long j= 0; j<length2; j++)
            {
                for( long k= 0; k<length1; k++)
                {
                    index[0]= k;
                    index[1]= j;
                    index[2]= i;
                    long longVal;
                    CComVariant var;
                    switch( type)
                    {
                    case VT_I4:
                        hr= SafeArrayGetElement( val, index, &longVal);
                        sprintf( tmpBuf, "(%ld,%ld,%ld): %ld\n", index[2], index[1], index[0], longVal);
                        break;
                    case VT_UI1:
                        hr= SafeArrayGetElement( val, index, &longVal);
                        sprintf( tmpBuf, "(%ld,%ld,%ld): %d\n", index[2], index[1], index[0], (unsigned char)longVal);
                        break;

                    case VT_VARIANT:
                        hr= SafeArrayGetElement( val, index, &var );
                        sprintf( tmpBuf, "(%ld,%ld,%ld):  %d (vartype %d)\n", index[2],  index[1], index[0], var.byref, var.vt);
                        break;
                    }
                    strcat( buff,tmpBuf);
                }
            }

        }

    }

    MessageBox( NULL, A2T( buff), _T("AxTestControl.Basic"), MB_OK);


}




STDMETHODIMP CBasic::outMore(long* val1, long* val2)
{
    // TODO: Add your implementation code here
    *val1= 111;
    *val2= 112;
    return S_OK;
}
// If an optional parameter was not provided then the respective member will
// not be set
STDMETHODIMP CBasic::optional1(/*[in]*/ long val1, /*[in, optional]*/ VARIANT* val2)
{
    m_long = val1;
    if (val2->vt != VT_ERROR)
        m_var1 = *val2;
    return S_OK;
}

STDMETHODIMP CBasic::optional2(/*[out]*/ long* val1,/*[out, optional]*/ VARIANT* val2)
{
    HRESULT hr = S_OK;
    *val1 = m_long;

    if (val2->vt != VT_ERROR)
        hr = VariantCopy(val2, & m_var1);
    return hr;
}

STDMETHODIMP CBasic::optional3(/*[in, optional]*/ VARIANT* val1,/*[in, optional]*/ VARIANT* val2)
{
    //if (val1->vt != VT_ERROR)
        m_var1 = *val1;

    //if (val2->vt != VT_ERROR)
        m_var2 = *val2;
    return S_OK;
}

STDMETHODIMP CBasic::optional4(/*[in, out, optional]*/ VARIANT* val1,
                               /*[in, out, optional]*/ VARIANT* val2)
{
    HRESULT hr = S_OK;
    //return the previously set in values
    if (val1->vt != VT_ERROR)
    {
        CComVariant var1(*val1);
        if (FAILED(hr = VariantCopy(val1, & m_var1)))
            return hr;
        m_var1 = var1;
    }
    if (val2->vt != VT_ERROR)
    {
        CComVariant var2(*val2);
        if (FAILED(hr = VariantCopy(val2, & m_var2)))
            return hr;
        m_var2 = var2;
    }
    return hr;
}

STDMETHODIMP CBasic::optional5(/*[out, optional]*/ VARIANT* val1,
                               /*[out, optional]*/ VARIANT* val2)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = VariantCopy(val1, &m_var1)))
        return hr;
    if (FAILED(hr = VariantCopy(val2, &m_var2)))
        return hr;
    return hr;
}

STDMETHODIMP CBasic::defaultvalue1(/*[in, defaultvalue(10)]*/ long val1,
                                   /*[in, defaultvalue(3.14)]*/ double* val2,
                                //   /*[in, defaultvalue(10)]*/ VARIANT val3,
                                   /*[in, defaultvalue(100)]*/ VARIANT* val4)
{
    m_long = val1;
    m_double = *val2;
//  m_var1 = val3;
    m_var2 = *val4;
    return S_OK;
}
STDMETHODIMP CBasic::defaultvalue2(/*[in, out, defaultvalue(10)]*/ long* val1,
                                   /*[in, out, defaultvalue(3.14)]*/ double* val2,
                                //   /*[in, out, defaultvalue(10)]*/ VARIANT* val3,
                                   /*[in, out, defaultvalue(100)]*/ VARIANT* val4)
{
    HRESULT hr = S_OK;
    long aLong = *val1;
    double aDouble = *val2;
//  CComVariant var1(*val3);
    CComVariant var2(*val4);
    *val1 = m_long;
    *val2 = m_double;
    //if (FAILED(hr = VariantCopy(val3, &m_var1)))
    //  return hr;
    if (FAILED(hr = VariantCopy(val4, &m_var2)))
        return hr;
    m_long = aLong;
    m_double = aDouble;
//  m_var1 = var1;
    m_var2 = var2;
    return hr;
}
/* val2 contains the variable argument list. If no such arguments are supplied
    then the safearray is invalid. SafeArrayCopy then returns E_INVALIDARG
*/
STDMETHODIMP CBasic::varargfunc1(/*[in]*/ long val1,/*[in]*/ LPSAFEARRAY val2)
{
    m_long = val1;

    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_safearray)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val2, & m_safearray)))
    {
        if (hr != E_INVALIDARG)
            return hr;
    }
    return S_OK;
}

STDMETHODIMP CBasic::varargfunc2(/*[out]*/ long* val1, /*[out]*/ SAFEARRAY ** val2)
{
    *val1 = m_long;
    HRESULT hr = SafeArrayCopy(m_safearray, val2);
    return hr;
}

STDMETHODIMP CBasic::inSequenceByteDim2(LPSAFEARRAY val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = SafeArrayDestroy(m_arByteDim2)))
        return hr;
    if (FAILED(hr = SafeArrayCopy(val, & m_arByteDim2)))
        return hr;
    return hr;
}


STDMETHODIMP CBasic::inCurrency(CY val)
{
    m_cy = val;
    return S_OK;
}

STDMETHODIMP CBasic::outCurrency(CY* val)
{
    *val = m_cy;
    return S_OK;
}

STDMETHODIMP CBasic::inoutCurrency(CY* val)
{
    CY tmp = *val;
    *val = m_cy;
    m_cy = tmp;
    return S_OK;
}

STDMETHODIMP CBasic::inDate(DATE val)
{
    m_date = val;
    return S_OK;
}

STDMETHODIMP CBasic::outDate(DATE* val)
{
    *val = m_date;
    return S_OK;
}

STDMETHODIMP CBasic::inoutDate(DATE* val)
{
    DATE tmp = *val;
    *val = m_date;
    m_date = tmp;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpCurrency(CY* pVal)
{
    *pVal = m_cy;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpCurrency(CY newVal)
{
    m_cy = newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpDate(DATE* pVal)
{
    *pVal = m_date;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpDate(DATE newVal)
{
    m_date = newVal;
    return S_OK;
}

//VT_I4 DECIMAL_NEG //tagVARIANT DISPATCH_PROPERTYPUT
STDMETHODIMP CBasic::inDecimal(DECIMAL val)
{
    m_decimal = val;
    return S_OK;
}

STDMETHODIMP CBasic::outDecimal(DECIMAL* val)
{
    * val = m_decimal;
    return S_OK;
}

STDMETHODIMP CBasic::inoutDecimal(DECIMAL* val)
{
    DECIMAL tmp;
    tmp = * val;
    * val = m_decimal;
    m_decimal = tmp;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpDecimal(DECIMAL* pVal)
{
    * pVal = m_decimal;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpDecimal(DECIMAL newVal)
{
    m_decimal = newVal;
    return S_OK;
}

STDMETHODIMP CBasic::inSCode(SCODE val)
{
    m_scode = val;
    return S_OK;
}

STDMETHODIMP CBasic::outScode(SCODE* val)
{
    * val = m_scode;
    return S_OK;
}

STDMETHODIMP CBasic::inoutSCode(SCODE* val)
{
    SCODE tmp = *val;
    * val = m_scode;
    m_scode = tmp;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpSCode(SCODE* pVal)
{
    * pVal = m_scode;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpSCode(SCODE newVal)
{
    m_scode = newVal;
    return S_OK;
}

STDMETHODIMP CBasic::inrefLong(LONG* val)
{
    m_long = * val;
    return S_OK;
}

STDMETHODIMP CBasic::inrefVariant(VARIANT* val)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = VariantCopy( & m_var1, val)))
        return hr;
    return S_OK;
}

STDMETHODIMP CBasic::inrefDecimal(DECIMAL* val)
{
    m_decimal = * val;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpRefLong(long* pVal)
{
    *pVal = m_long;
    return S_OK;
}

STDMETHODIMP CBasic::putref_prpRefLong(long* newVal)
{
    m_long = * newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prprefVariant(VARIANT* pVal)
{
    HRESULT hr = S_OK;
    hr = VariantCopy(pVal, & m_var1);
    return hr;
}

STDMETHODIMP CBasic::putref_prprefVariant(VARIANT* newVal)
{
    m_var1 = * newVal;
    return S_OK;
}

STDMETHODIMP CBasic::get_prprefDecimal(DECIMAL* pVal)
{
    * pVal = m_decimal;
    return S_OK;
}

STDMETHODIMP CBasic::putref_prprefDecimal(DECIMAL* newVal)
{
    m_decimal = *newVal;
    return S_OK;
}


STDMETHODIMP CBasic::optional6(VARIANT* val1, VARIANT* val2, VARIANT* val3, VARIANT* val4)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = m_var1.Copy(val1)))
        return hr;
    if (FAILED(hr = m_var2.Copy(val2)))
        return hr;
    if (FAILED(hr = m_var3.Copy(val3)))
        return hr;
    if (FAILED(hr = m_var4.Copy(val4)))
        return hr;
    return S_OK;
}

STDMETHODIMP CBasic::optional7(VARIANT* val1, VARIANT* val2, VARIANT* val3, VARIANT* val4)
{
    HRESULT hr = S_OK;
    if (FAILED(hr = VariantCopy(val1, & m_var1)))
        return hr;
    if (FAILED(hr = VariantCopy(val2, & m_var2)))
        return hr;
    if (FAILED(hr = VariantCopy(val3, & m_var3)))
        return hr;
    if (FAILED(hr = VariantCopy(val4, & m_var4)))
        return hr;

    return S_OK;
}

STDMETHODIMP CBasic::get_prpMultiArg1(VARIANT* val1, VARIANT* val2, VARIANT* pVal)
{
    HRESULT hr = S_OK;
    CComVariant tmp1(*val1);
    CComVariant tmp2(*val2);

    if (FAILED(hr = VariantCopy(val1, & m_var1)))
        return hr;
    if (FAILED(hr = VariantCopy(val2, & m_var2)))
        return hr;
    m_var1 = tmp1;
    m_var2 = tmp2;
    if  (FAILED(hr = VariantCopy(pVal, & m_var3)))
        return hr;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpMultiArg1(VARIANT* val1, VARIANT* val2, VARIANT* newVal)
{
    HRESULT hr = S_OK;
    CComVariant tmp1( * val1);
    CComVariant tmp2( * val2);

    if (FAILED(hr = VariantCopy(val1, & m_var1)))
        return hr;
    if (FAILED(hr = VariantCopy(val2, & m_var2)))
        return hr;
    m_var1 = tmp1;
    m_var2 = tmp2;

    m_var3 = *newVal;
    return S_OK;
}

// tagVARIANT DISPATCH_PROPERTYPUT DISPID_PROPERTYPUT VARIANTARG LOCALE_USER_DEFAULT

STDMETHODIMP CBasic::get_prpMultiArg2(VARIANT val1, VARIANT* pVal)
{
    HRESULT hr = S_OK;
    m_var1 =  val1;

    if (FAILED(hr = VariantCopy(pVal, & m_var2)))
        return hr;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpMultiArg2(VARIANT val1, VARIANT newVal)
{
    m_var1 = val1;
    m_var2 = newVal;
    return S_OK;
}

// returns the values set by prpMultiArg2
STDMETHODIMP CBasic::prpMultiArg2GetValues(VARIANT* val1, VARIANT* valProperty)
{
    HRESULT hr = S_OK;
    if (FAILED(VariantCopy(val1, & m_var1)))
        return hr;
    if (FAILED(VariantCopy(valProperty, & m_var2)))
        return hr;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpMultiArg3(LONG* val1, LONG* pVal)
{
    long aLong = *val1;
    *val1 = m_long;
    m_long = aLong;

    * pVal = m_long2;
    return S_OK;
}

STDMETHODIMP CBasic::put_prpMultiArg3(LONG* val1, LONG newVal)
{
    long aLong = *val1;
    *val1 = m_long;
    m_long = aLong;

    m_long2 = newVal;
    return S_OK;
}

STDMETHODIMP CBasic::inUnknown(IUnknown* val)
{
    m_unknown = val;

    return S_OK;
}

STDMETHODIMP CBasic::outUnknown(IUnknown** val)
{
    m_unknown.CopyTo(val);
    return S_OK;
}

STDMETHODIMP CBasic::inoutUnknown(IUnknown** val)
{
    CComPtr<IUnknown> tmp = *val;
    m_unknown.CopyTo(val);
    m_unknown = tmp;
    return S_OK;
}

STDMETHODIMP CBasic::get_prpUnknown(IUnknown** pVal)
{
    m_prpUnknown.CopyTo(pVal);
    return S_OK;
}

STDMETHODIMP CBasic::put_prpUnknown(IUnknown* newVal)
{
    m_prpUnknown = newVal;
    return S_OK;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */