summaryrefslogtreecommitdiff
path: root/extensions/test/ole/OleClient/clientTest.cxx
blob: 2c53e29b52a5e0b7c8f8be237172078a1c12c938 (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
/*************************************************************************
 *
 *  $RCSfile: clientTest.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: jl $ $Date: 2001-06-27 10:59:56 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#include <com/sun/star/bridge/ModelDependent.hpp>
#include <com/sun/star/bridge/XBridgeSupplier2.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/script/XInvocation.hpp>
#include <oletest/XCallback.hpp>
#include <rtl/process.h>
#include <com/sun/star/uno/Reference.h>
#include <cppuhelper/servicefactory.hxx>
#include <rtl/string.h>
#pragma hdrstop


//#include <windows.h>
#include <comdef.h>
//#include <tchar.h>
#include <windef.h>
#include <atlbase.h>

// actually defined in windef.h but after altbase.h it is undefined
// it is used in atlcom.h
#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

extern CComModule _Module;


#include<atlcom.h>
#include<atlimpl.cpp>

#include "axhost.hxx"

CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()

using namespace com::sun::star::lang;
using namespace com::sun::star::uno;
using namespace com::sun::star::script;
using namespace com::sun::star::bridge;
using namespace com::sun::star::bridge::ModelDependent;
using namespace cppu;
using namespace rtl;
HRESULT doTest();
HRESULT doTest2( Reference<XInvocation> &);
Reference<XInvocation> getComObject(OUString& );

HRESULT InitializeParameter();
void printResultVariantArray( VARIANT & var);
void printVariant( VARIANT & var);
void printSequence( Sequence<Any>& val);


Reference< XMultiServiceFactory > objectFactory;// OleObjectFactory;


int __cdecl _tmain( int argc, _TCHAR * argv[] )
{
    HRESULT hr;
    if( FAILED( hr=CoInitialize(NULL)))
    {
        _tprintf(_T("CoInitialize failed \n"));
        return -1;
    }


    _Module.Init( ObjectMap, GetModuleHandle( NULL));

    if( FAILED(hr=doTest()))
    {
        _com_error err( hr);
        const TCHAR * errMsg= err.ErrorMessage();
        MessageBox( NULL, errMsg, "Test failed", MB_ICONERROR);
    }


    _Module.Term();
    CoUninitialize();
    return 0;
}

Reference<XMultiServiceFactory> getMultiServiceFactory()
{
    static Reference< XMultiServiceFactory > factory;
    if( ! objectFactory.is() )
    {
        Reference<XInterface> xint= createRegistryServiceFactory( OUString(L"applicat.rdb"));
        factory= Reference<XMultiServiceFactory>( xint, UNO_QUERY);
    }
    return factory;
}

Reference<XInvocation> getComObject( OUString progId)
{
    HRESULT hr= S_OK;
    Reference< XInvocation > ret;
//  Reference<XMultiServiceFactory> fac;
    if(  ! objectFactory.is())
    {   Reference<XMultiServiceFactory> mgr= getMultiServiceFactory();
        Reference< XInterface > xInt= mgr->createInstance( OUString(L"com.sun.star.bridge.OleObjectFactory"));
        objectFactory= Reference<XMultiServiceFactory>::query(  xInt);
    }

    if( objectFactory.is())
    {
        Reference<XInterface> xIntAx= objectFactory->createInstance( progId.getStr());
        if( xIntAx.is() )
        {
            Reference< XInvocation > xInv( xIntAx, UNO_QUERY);
            ret= xInv;
        }
    }
    return ret;
}

Reference<XInvocation> convertComObject( IUnknown* pUnk)
{
    Reference< XMultiServiceFactory > mgr= getMultiServiceFactory();
    Reference< XInterface > xIntSupplier= mgr->createInstance(OUString(L"com.sun.star.bridge.OleBridgeSupplier2"));
    Reference< XBridgeSupplier2 > xSuppl( xIntSupplier, UNO_QUERY);

    Any any;
    CComVariant var( pUnk);
    any <<= ( sal_uInt32)&var;
    sal_uInt8 arId[16];
    rtl_getGlobalProcessId( arId);
    Any target= xSuppl->createBridge( any, Sequence<sal_Int8>( (sal_Int8*)arId, 16), OLE, UNO );

    Reference<XInvocation> ret;
    target>>= ret;
    return ret;
}

HRESULT doTest()
{
    HRESULT hr= S_OK;
    USES_CONVERSION;
    Reference<XInvocation> inv= getComObject( L"AxTestComponents.Basic");

    HostWin* pWin= new HostWin( L"MFCCONTROL.MfcControlCtrl.1");
    CComPtr<IUnknown> spUnk= pWin->GetHostedControl();
    Reference<XInvocation> invMfc= convertComObject( spUnk.p);

    Sequence< sal_Int16> seqIndices;
    Sequence<Any> seqOut;

    Any aAny;
    Any anyOut;
    char buff[1024];
    Any seqAny;

    //###################################################################################
    //  in parameter
    //###################################################################################
    aAny <<= ( sal_Int8) 127;
    inv->invoke( OUString(L"inByte"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    aAny <<= ( sal_Int16) 0xffff;
    inv->invoke( OUString(L"inShort"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
//
    aAny <<= ( sal_Int32) 1234567;
    inv->invoke( OUString(L"inLong"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    aAny <<= OUString(L" this is clientTest.exe");
    inv->invoke( OUString(L"inString"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    aAny <<= ( float) 3.14;
    inv->invoke( OUString(L"inFloat"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    aAny <<= ( double) 3.145;
    inv->invoke( OUString(L"inDouble"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    aAny <<= OUString( L" A string in an any");
    inv->invoke( OUString(L"inVariant"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    OUString arStr[]= {L"string0", L"string1", L"string2"};
    Sequence<OUString> seq( arStr, 3);
    Any arAny[1];
    arAny[0] <<= seq;
    inv->invoke( OUString(L"inArray"), Sequence< Any > ( arAny, 1), seqIndices, seqOut);

    // same again but this time Sequence<Any> with the Anys containing strings.
    OUString arStr1[]= {L"string0", L"string1", L"string2"};
    Any arAnyStr1[3];
    arAnyStr1[0]<<= arStr1[0];
    arAnyStr1[1]<<= arStr1[1];
    arAnyStr1[2]<<= arStr1[2];
    Sequence<Any> seq_1( arAnyStr1, 3);
    Any arAny_1[1];
    arAny_1[0] <<= seq_1;
    inv->invoke( OUString(L"inArray"), Sequence< Any > ( arAny_1, 1), seqIndices, seqOut);
//
    Reference < XInvocation > inv2= getComObject(L"AxTestComponents.Basic");
    Any anyVal;
    anyVal <<= OUString(L"this is the value of prpString");
    inv2->setValue( OUString(L"prpString"), anyVal);
    aAny <<= inv2;
    inv->invoke( OUString(L"inObject"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    //###################################################################################
    //  out parameter
    //###################################################################################
//  // outByte
    aAny= Any();
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outByte"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " out Byte: %d", *( char*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    // outShort
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outShort"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " out Short: %d", *( sal_Int16*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    // outLong
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outLong"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " out Long: %d", *( sal_Int32*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    // outString
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outString"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " out String: %S", (*( OUString*)anyOut.getValue()).getStr());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    // outFloat
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outFloat"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " out float: %f", *( float*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    // outDouble
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outDouble"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " out double: %g", *( double*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);
//
//  // outVariant
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outVariant"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    if( anyOut.getValueTypeClass() == TypeClass_STRING)
    {
        OUString s;
        anyOut >>= s;
        sprintf( buff, " out string ( variant): %S", s.getStr());
        MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);
    }

    // outArray
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outArray"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    Sequence<Any> seqOutValue;
    anyOut >>= seqOutValue;

    // we assume that the Sequence contains Anys of strings
    OUString usMessage;
    for( int i=0; i < seqOutValue.getLength(); i++)
    {
        OUString stemp;
        if( seqOutValue[i] >>= stemp)
        {
            usMessage += OUString(L"\n");
            usMessage += stemp;
        }
    }
    MessageBox( NULL, W2T( usMessage.getStr()), _T("Test Program"), MB_OK);

    // outObject
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    inv->invoke(  OUString(L"outObject"), Sequence< Any > ( &aAny, 1 ), seqIndices, seqOut);
    Reference<XInvocation> invOut;
    if( seqOut[0]>>=invOut)
    {
        Any val=    invOut->getValue( L"prpString");

        if( val.getValueTypeClass() == TypeClass_STRING)
        {
            OUString s;
            val>>=s;
            MessageBox( NULL,W2T( s.getStr()), _T("Test Program"), MB_OK);
        }
    }
//
    //###################################################################################
    //  in/out parameter
    //###################################################################################
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    aAny <<= ( sal_Int8) 127;
    inv->invoke( OUString(L"inoutByte"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " in out Byte: %d", *( char*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);
//
//  // in out short
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    aAny <<= ( sal_Int16) 1111;
    inv->invoke( OUString(L"inoutShort"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " in out Short: %d", *( sal_Int16*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    //in out long
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    aAny <<= ( sal_Int32) 111111;
    inv->invoke( OUString(L"inoutLong"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, "inout Long: %d", *( sal_Int32*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    //in out string
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    aAny <<= OUString(L" this is clientTest.exe");
    inv->invoke( OUString(L"inoutString"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " inout String: %S", (*( OUString*)anyOut.getValue()).getStr());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    //in out float
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    aAny <<= ( float) 3.14;
    inv->invoke( OUString(L"inoutFloat"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " inout float: %f", *( float*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    // in out double
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    aAny <<= ( double) 3.145;
    inv->invoke( OUString(L"inoutDouble"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    sprintf( buff, " inout double: %g", *( double*)anyOut.getValue());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    // in out VARIANT
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    aAny <<= OUString( L" A string in an any");
    inv->invoke( OUString(L"inoutVariant"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut <<= seqOut[0];
    if( anyOut.getValueTypeClass() == TypeClass_STRING)
    {
        OUString s;
        anyOut >>= s;
        sprintf( buff, " in out string ( variant): %S", s.getStr());
        MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);
    }
//
    // in out Array
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    OUString arStr2[]= {L"string0", L"string1", L"string2"};
    Sequence<OUString> seq2( arStr2, 3);
    Any arAny2[1];
    arAny2[0] <<= seq2;
    inv->invoke( OUString(L"inoutArray"), Sequence< Any > ( arAny2, 1), seqIndices, seqOut);
    Sequence<Any> seqOutValue2;
    seqOut[0]>>= seqOutValue2;

    // we assume that the Sequence contains Anys of strings
    OUString usMessage2;
    for(int  i2=0; i2 < seqOutValue2.getLength(); i2++)
    {
        OUString stemp;
        if( seqOutValue2[i2] >>= stemp)
        {
            usMessage2 += OUString(L"\n");
            usMessage2 += stemp;
        }
    }
    MessageBox( NULL, W2T( usMessage2.getStr()), _T("Test Program"), MB_OK);
//

    seqIndices.realloc( 0);
    seqOut.realloc(0);
    Reference < XInvocation > inv3= getComObject(L"AxTestComponents.Basic");
    Any anyVal2;
    anyVal2 <<= OUString(L"this is the value of prpString");
    inv3->setValue( OUString(L"prpString"), anyVal2);
    aAny <<= inv3;
    inv->invoke( OUString(L"inoutObject"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    Reference<XInvocation> invOut2;
    if( seqOut[0]>>=invOut2)
    {
        Any val=    invOut2->getValue( L"prpString");

        if( val.getValueTypeClass() == TypeClass_STRING)
        {
            OUString s;
            val>>=s;
            MessageBox( NULL,W2T( s.getStr()), _T("Test Program"), MB_OK);
        }
    }
//
//  //###################################################################################
//  //  mixed parameter
//  //###################################################################################
    // mixed1
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    Sequence< Any > params(12);
    sal_Int8 aByte=111;
    OUString aString(L" a string in a VARIANT");
    Any param[12];
    param[0] <<= aByte;
    param[2] <<= aByte; //in out
    param[3] <<= aString; // in String
    param[5] <<= aString; // in out string

    OUString arStr3[]= {L"string0", L"string1", L"string2"};
    Sequence<OUString> seq3( arStr3,3);
    param[6] <<= seq3;  // in Array
    param[8] <<= seq3;  // in ou Array

    Reference < XInvocation > inv4= getComObject(L"AxTestComponents.Basic");
    Any anyVal3;
    anyVal3 <<= OUString(L"this is the value of prpString");
    inv4->setValue( OUString(L"prpString"), anyVal3);
    param[9] <<= inv4; // in dispatch
    param[11] <<= inv4;
    inv->invoke( OUString(L"mixed1"), Sequence< Any > ( param, 12),seqIndices, seqOut);

    for( int i3=0; i3<seqOut.getLength();i3++)
    {
        Any any;
        any <<= seqOut[i3];

    }
    sal_Int8 outChar= *( char*)seqOut[0].getValue();
    sal_Int8 inoutChar= *( char*)seqOut[1].getValue();
    sprintf( buff, " out Byte: %d \n in out Byte %d", outChar, inoutChar );
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    OUString outString( *(OUString*)seqOut[2].getValue());
    OUString inoutString( *(OUString*)seqOut[3].getValue());
    sprintf( buff, "out string: %S \n in out string: %S", outString.getStr(), inoutString.getStr());
    MessageBox( NULL, A2T( buff), _T("Test Program"), MB_OK);

    Sequence< Any > outSeq;
    seqOut[4] >>= outSeq;
    OUString usMessage3;
    for(int  i4=0; i4 < outSeq.getLength(); i4++)
    {
        OUString stemp;
        if( outSeq[i4] >>= stemp)
        {
            usMessage3 += OUString(L"\n");
            usMessage3 += stemp;
        }
    }
    MessageBox( NULL, W2T( usMessage3.getStr()), _T("Test Program. out Sequence"), MB_OK);

    seqOut[5] >>= outSeq;
    OUString usMessage4;
    for(int  i5=0; i5 < outSeq.getLength(); i5++)
    {
        OUString stemp;
        if( outSeq[i5] >>= stemp)
        {
            usMessage4 += OUString(L"\n");
            usMessage4 += stemp;
        }
    }
    MessageBox( NULL, W2T( usMessage3.getStr()), _T("Test Program. in out Sequence"), MB_OK);

    Reference<XInvocation> invOut3;
    seqOut[6] >>= invOut3;
    if( seqOut[0]>>=invOut3)
    {
        Any val=    invOut3->getValue( L"prpString");

        if( val.getValueTypeClass() == TypeClass_STRING)
        {
            OUString s;
            val>>=s;
            MessageBox( NULL,W2T( s.getStr()), _T("Test Program, out object"), MB_OK);
        }
    }

    Reference<XInvocation> invOut4;
    seqOut[6] >>= invOut4;
    if( seqOut[0]>>=invOut4)
    {
        Any val=    invOut4->getValue( L"prpString");

        if( val.getValueTypeClass() == TypeClass_STRING)
        {
            OUString s;
            val>>=s;
            MessageBox( NULL,W2T( s.getStr()), _T("Test Program, in out object"), MB_OK);
        }
    }
//
//  //###################################################################################
//  //  in Sequences
//  //###################################################################################
//  // inSequenceLong
    seqIndices.realloc( 0);
    seqOut.realloc(0);
    sal_Int32 arLong[]={ 1,2,3};
    Sequence< sal_Int32 > seqLong( arLong, 3);

    //  seqLongAny <<= seqLong; // 1 dimension
    //      seqLongAny<<= seq; // 2 dimensions
    //  seqLongAny<<= seq1;
    //  seqLongAny<<= Sequence<sal_Int32>( arLong, 3);

    seqAny<<= seqLong;
    inv->invoke( OUString(L"inSequenceLong"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
//
//  // inSequenceShort
    sal_Int16 arShort[]={1,2,3};
    Sequence<sal_Int16> seqShort(arShort, 3);
    seqAny<<= seqShort;
    inv->invoke( OUString(L"inSequenceShort"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
//
//  // inSequenceByte
    sal_Int8 arByte[]={1,2,3};
    Sequence<sal_Int8> seqByte(arByte, 3);
    seqAny<<= seqByte;
    inv->invoke( OUString(L"inSequenceByte"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
//
//  // inSequenceString
    OUString arString[]={L"string one", L"string two", L"string three"};
    Sequence<OUString> seqString( arString, 3);
    seqAny<<= seqString;
    inv->invoke( OUString(L"inSequenceString"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
//
//  // inSequenceFloat
    float arFloat[]={3.14, 31.4, 314.};
    Sequence<float> seqFloat( arFloat, 3);
    seqAny<<=seqFloat;
    inv->invoke( OUString(L"inSequenceFloat"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
//
//  // inSequenceDouble
    double arDouble[]={3.14, 31.4, 314.};
    Sequence<double> seqDouble( arDouble, 3);
    seqAny<<=seqDouble;
    inv->invoke( OUString(L"inSequenceDouble"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
//
//
//  // inSequenceObject
    Any anyVala;
    OUString sVal;
    Sequence<Reference<XInvocation> > seqObj(3);
    seqObj[0]=  getComObject(L"AxTestComponents.Basic");
    sVal= L"this is the property value of prpString (1)";
    anyVala<<= sVal;
    seqObj[0]->setValue( OUString( L"prpString"), anyVala);

    seqObj[1]=  getComObject(L"AxTestComponents.Basic");
    sVal= L"this is the property valuef of prpString (2)";
    anyVala<<= sVal;
    seqObj[1]->setValue( OUString( L"prpString"), anyVala);

    seqObj[2]=  getComObject(L"AxTestComponents.Basic");
    sVal= L"this is the property value of prpString (3)";
    anyVala<<= sVal;
    seqObj[2]->setValue( OUString( L"prpString"), anyVala);

    seqAny<<=seqObj;
    inv->invoke( OUString(L"inSequenceObject"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
//
//  //###################################################################################
//  //  out Sequences
//  //###################################################################################
//
//  // outSequenceByte
//
    inv->invoke( OUString(L"outSequenceByte"),Sequence< Any > (), seqIndices, seqOut);
    printSequence( *(Sequence<Any>*)seqOut[0].getValue());


    // outSequenceShort
    inv->invoke( OUString(L"outSequenceShort"),Sequence< Any > (), seqIndices, seqOut);
    printSequence(*(Sequence<Any>*)seqOut[0].getValue());


    // outSequenceLong
    inv->invoke( OUString(L"outSequenceLong"),Sequence< Any > (), seqIndices, seqOut);
    printSequence(*(Sequence<Any>*)seqOut[0].getValue());

    // outSequenceString
    inv->invoke( OUString(L"outSequenceString"),Sequence< Any > (), seqIndices, seqOut);
    printSequence(*(Sequence<Any>*)seqOut[0].getValue());

    // outSequenceFloat
    inv->invoke( OUString(L"outSequenceFloat"),Sequence< Any > (), seqIndices, seqOut);
    printSequence(  *(Sequence<Any>*)seqOut[0].getValue());


    //outSequenceDouble
    inv->invoke( OUString(L"outSequenceDouble"),Sequence< Any > (), seqIndices, seqOut);
    printSequence(*(Sequence<Any>*)seqOut[0].getValue());
//
//  //outSequenceObject
    inv->invoke( OUString(L"outSequenceObject"),Sequence< Any > (), seqIndices, seqOut);
    printSequence(  *(Sequence<Any>*)seqOut[0].getValue());
//
//  // outSequenceVariant (see outArray)
//  //###################################################################################
//  //  in out Sequences
//  //###################################################################################
//  // inoutSequenceByte
    sal_Int8 arByte1[]={1,2,3};
    Sequence<sal_Int8> seqByteIO(arByte1, 3);
    seqAny<<= seqByteIO;
    inv->invoke( OUString(L"inoutSequenceByte"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
    printSequence( *(Sequence<Any>*)seqOut[0].getValue());

    // inoutSequenceShort
    sal_Int16 arShort1[]={1,2,3};
    Sequence<sal_Int16> seqShortIO(arShort1, 3);
    seqAny<<= seqShortIO;
    inv->invoke( OUString(L"inoutSequenceShort"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
    printSequence( *(Sequence<Any>*)seqOut[0].getValue());


    // inoutSequenceLong
    sal_Int32 arLong1[]={ 1,2,3};
    Sequence< sal_Int32 > seqLongIO( arLong1, 3);
    seqAny<<= seqLongIO;
    inv->invoke( OUString(L"inoutSequenceLong"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
    printSequence( *(Sequence<Any>*)seqOut[0].getValue());

    // inoutSequenceString
    OUString arString1[]={L"string one", L"string two", L"string three"};
    Sequence<OUString> seqStringIO( arString1, 3);
    seqAny<<= seqStringIO;
    inv->invoke( OUString(L"inoutSequenceString"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
    printSequence( *(Sequence<Any>*)seqOut[0].getValue());

    // inoutSequenceFloat
    float arFloat1[]={3.14, 31.4, 314.};
    Sequence<float> seqFloatIO( arFloat1, 3);
    seqAny<<=seqFloatIO;
    inv->invoke( OUString(L"inoutSequenceFloat"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
    printSequence( *(Sequence<Any>*)seqOut[0].getValue());

    // inoutSequenceDouble
    double arDouble1[]={3.14, 31.4, 314.};
    Sequence<double> seqDoubleIO( arDouble1, 3);
    seqAny<<=seqDoubleIO;
    inv->invoke( OUString(L"inoutSequenceDouble"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
    printSequence( *(Sequence<Any>*)seqOut[0].getValue());
//
//
//  // inoutSequenceObject
    Any anyValb;
    OUString sVala;
    Sequence<Reference<XInvocation> > seqObjIO(3);
    seqObjIO[0]=    getComObject(L"AxTestComponents.Basic");
    sVala= L"this is the property value of prpString (1)";
    anyValb<<= sVala;
    seqObjIO[0]->setValue( OUString( L"prpString"), anyValb);

    seqObjIO[1]=    getComObject(L"AxTestComponents.Basic");
    sVala= L"this is the property valuef of prpString (2)";
    anyValb<<= sVala;
    seqObjIO[1]->setValue( OUString( L"prpString"), anyValb);

    seqObjIO[2]=    getComObject(L"AxTestComponents.Basic");
    sVala= L"this is the property value of prpString (3)";
    anyValb<<= sVala;
    seqObjIO[2]->setValue( OUString( L"prpString"), anyValb);

    seqAny<<=seqObjIO;
    inv->invoke( OUString(L"inoutSequenceObject"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
    printSequence( *(Sequence<Any>*)seqOut[0].getValue());
//
//  //###################################################################################
//  //  in multi Sequences
//  //###################################################################################
//  // inMulDimArrayLong
    sal_Int32 arLongi[]={1,2,3};
    sal_Int32 arLongi2[]={4,5,6,7};
    sal_Int32 arLongi3[]={8,9,10,11,12};

    Sequence<sal_Int32> seqLongi1( arLongi, 3);
    Sequence<sal_Int32> seqLongi2( arLongi2, 4);
    Sequence<sal_Int32> seqLongi3( arLongi3, 5);

    Sequence< Sequence< sal_Int32 > > seq2i(3);
    seq2i[0]= seqLongi1;
    seq2i[1]= seqLongi2;
    seq2i[2]= seqLongi3;
    seqAny<<= seq2i;
    // dimension length 3,5
    inv->invoke( OUString(L"inMulDimArrayLong"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);
//
    //inMulDimArrayVariant
    inv->invoke( OUString(L"inMulDimArrayVariant"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);

    //inMulDimArrayLong2
    sal_Int32 arLongii1[]={1,2,3};
    sal_Int32 arLongii2[]={4,5,6,7};
    sal_Int32 arLongii3[]={8,9,10,11,12};
    sal_Int32 arLongii4[]={13,14,15,16};
    sal_Int32 arLongii5[]={17,18,19};

    Sequence<sal_Int32> seqLongii1( arLongii1, 3);
    Sequence<sal_Int32> seqLongii2( arLongii2, 4);
    Sequence<sal_Int32> seqLongii3( arLongii3, 5);
    Sequence<sal_Int32> seqLongii4( arLongii4, 4);
    Sequence<sal_Int32> seqLongii5( arLongii5, 3);

    Sequence< Sequence< sal_Int32 > > seq2ii(3);
    Sequence< Sequence< sal_Int32> > seq2ii2(2);
    seq2ii[0]= seqLongii1;
    seq2ii[1]= seqLongii2;
    seq2ii[2]= seqLongii3;

    seq2ii2[0]= seqLongii4;
    seq2ii2[1]= seqLongii5;

    Sequence< Sequence< Sequence< sal_Int32> > >  seq3ii(2);
    seq3ii[0]=seq2ii;
    seq3ii[1]=seq2ii2;
    seqAny<<= seq3ii;
    inv->invoke( OUString(L"inMulDimArrayLong2"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);

    // inMulDimArrayByte2
    sal_Int8 arByteii1[]={1,2,3};
    sal_Int8 arByteii2[]={4,5,6,7};
    sal_Int8 arByteii3[]={8,9,10,11,12};
    sal_Int8 arByteii4[]={13,14,15,16};
    sal_Int8 arByteii5[]={17,18,19};

    Sequence<sal_Int8> seqByteii1( arByteii1, 3);
    Sequence<sal_Int8> seqByteii2( arByteii2, 4);
    Sequence<sal_Int8> seqByteii3( arByteii3, 5);
    Sequence<sal_Int8> seqByteii4( arByteii4, 4);
    Sequence<sal_Int8> seqByteii5( arByteii5, 3);

    Sequence< Sequence< sal_Int8 > > seq2Byteii(3);
    Sequence< Sequence< sal_Int8> > seq2Byteii2(2);
    seq2Byteii[0]= seqByteii1;
    seq2Byteii[1]= seqByteii2;
    seq2Byteii[2]= seqByteii3;

    seq2Byteii2[0]= seqByteii4;
    seq2Byteii2[1]= seqByteii5;

    Sequence< Sequence< Sequence< sal_Int8> > >  seq3Byteii(2);
    seq3Byteii[0]=seq2Byteii;
    seq3Byteii[1]=seq2Byteii2;
    seqAny<<= seq3Byteii;
    inv->invoke( OUString(L"inMulDimArrayByte2"),Sequence< Any > ( &seqAny, 1), seqIndices, seqOut);


    // prpByte
    Any prpAny;
    sal_Int8 aByte1= 111;
    prpAny<<= aByte1;
    inv->setValue(OUString(L"prpByte"), prpAny);
    prpAny= Any();
    aByte1=0;
    prpAny= inv->getValue(OUString(L"prpByte"));
    prpAny>>= aByte1;
    // prpShort

    // prpLong
    //###################################################################################
    //###################################################################################
    //###################################################################################
    //  Tests with a MFC ActiveX control, ( pure dispinterface)
    //###################################################################################

    //###################################################################################
    //  in parameter MFC ActiveX
    //###################################################################################
    // unsigned char is not supported by MFC
    //  aAny <<= ( sal_Int8) 127;
    //  invMfc->invoke( OUString(L"inByte"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    aAny <<= ( sal_Int16) 0xffff;
    aAny= invMfc->invoke( OUString(L"inShort"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

//
    aAny <<= ( sal_Int32) 1234567;
    aAny=invMfc->invoke( OUString(L"inLong"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    sal_Int32 retLong= *(sal_Int32*)aAny.getValue();

    OUString str_1(L" this is clientTest.exe");
    aAny <<= str_1;
    aAny=invMfc->invoke( OUString(L"inString"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    aAny>>= str_1;

    aAny <<= ( float) 3.14;
    aAny=invMfc->invoke( OUString(L"inFloat"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    aAny <<= ( double) 3.145;
    aAny=invMfc->invoke( OUString(L"inDouble"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    aAny <<= OUString( L" A string in an any");
    aAny=invMfc->invoke( OUString(L"inVariant"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);

    // Tests with Sequences later.
    //  OUString arStr4[]= {L"string0", L"string1", L"string2"};
    //  Sequence<OUString> seqStr4( arStr4, 3);
    //  aAny <<= seqStr4;
    //  invMfc->invoke( OUString(L"inArray"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);


    Reference < XInvocation > inv5= getComObject(L"AxTestComponents.Basic");
    Any anyVal4;
    anyVal4 <<= OUString(L"this is the value of prpString");
    inv5->setValue( OUString(L"prpString"), anyVal4);
    aAny <<= inv5;
    aAny=invMfc->invoke( OUString(L"inObject"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
//
//  //###################################################################################
//  //  out parameter MFC ActiveX
//  //###################################################################################
//
//  // outShort
    aAny= invMfc->invoke( OUString(L"outShort"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut<<= seqOut[0];
    sprintf(buff, "MFC outShort %d",  *(sal_Int16*)anyOut.getValue());
    MessageBox( NULL, buff, _T("clientTest"), MB_OK);

    // outLong
    aAny= invMfc->invoke( OUString(L"outLong"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut<<= seqOut[0];
    sprintf(buff, "MFC outLong %d",  *(sal_Int32*)anyOut.getValue());
    MessageBox( NULL, buff, _T("clientTest"), MB_OK);

    // outString
    aAny= invMfc->invoke( OUString(L"outString"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut<<= seqOut[0];
    sprintf(buff, "MFC outString %S",  ((OUString*)anyOut.getValue())->getStr());
    MessageBox( NULL, buff, _T("clientTest"), MB_OK);

    // outFloat
    aAny= invMfc->invoke( OUString(L"outFloat"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut<<= seqOut[0];
    sprintf(buff, "MFC outFloat %f",  *(float*)anyOut.getValue());
    MessageBox( NULL, buff, _T("clientTest"), MB_OK);

    // outDouble
    aAny= invMfc->invoke( OUString(L"outDouble"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut<<= seqOut[0];
    sprintf(buff, "MFC outFloat %f",  *(double*)anyOut.getValue());
    MessageBox( NULL, buff, _T("clientTest"), MB_OK);

    // outVariant
    // we expect a string!! ( VT_BSTR)
    aAny= invMfc->invoke( OUString(L"outVariant"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    anyOut<<= seqOut[0];
    sprintf(buff, "MFC outVariant %S", ((OUString*)anyOut.getValue())->getStr());
    MessageBox( NULL, buff, _T("clientTest"), MB_OK);

    // outDouble
    aAny= invMfc->invoke( OUString(L"outObject"), Sequence< Any > ( &aAny, 1), seqIndices, seqOut);
    Reference<XInvocation> invOut5;
    seqOut[0]>>= invOut5;
    // we assume that an object of AxTestControls.Basic is being returned.
    anyOut= invOut5->getValue( OUString(L"prpString"));
    OUString tmpStr;
    anyOut>>=tmpStr;
    sprintf(buff, "MFC outObject, property:  %S",  tmpStr.getStr());
    MessageBox( NULL, buff, _T("clientTest"), MB_OK);


    //###################################################################################
    //  Sequence parameter MFC ActiveX
    //###################################################################################
    // Sequences are not directly supported.


    delete pWin;
    return hr;

}


void printSequence( Sequence<Any>& val)
{

//  typelib_TypeDescription* desc;
//  val.getValueTypeDescription( &desc);
//  typelib_typedescription_release( desc);

    USES_CONVERSION;
    char buff[1024];
    buff[0]=0;
    char tmpBuf[1024];
    tmpBuf[0]=0;
    sal_Int32 i;

    for( i=0; i< val.getLength(); i++)
    {
        Any& elem= val[i];
        switch ( elem.getValueTypeClass())
        {
        case TypeClass_BYTE:
             sprintf( tmpBuf, "sal_Int8 %d \n", *(sal_Int8*)elem.getValue());
             break;
        case TypeClass_SHORT:
             sprintf( tmpBuf, "sal_Int16 %d \n", *(sal_Int16*)elem.getValue());
             break;
        case TypeClass_LONG:
             sprintf( tmpBuf, "sal_Int32 %d \n", *(sal_Int32*)elem.getValue());
             break;
        case TypeClass_DOUBLE:
             sprintf( tmpBuf, "double %f \n", *(double*)elem.getValue());
             break;
        case TypeClass_FLOAT:
             sprintf( tmpBuf, "float %f \n", *(float*)elem.getValue());
             break;
        case TypeClass_STRING:
             sprintf( tmpBuf, "%S \n", (*(OUString*)elem.getValue()).getStr());
             break;
        case TypeClass_INTERFACE:
            {
            // we assume that the interface is XInvocation of a AxTestControls.Basic component.
            Reference<XInvocation> inv;
            elem>>= inv;
            if( inv.is())
            {
                Any prpVal= inv->getValue( OUString( L"prpString"));
                sprintf( tmpBuf, "Property prpString: %S \n", (*(OUString*)prpVal.getValue()).getStr());
            }
            break;
            }
        default:break;
        }
        strcat( buff, tmpBuf);

    }

    MessageBox( NULL, A2T(buff), _T("clientTest: printing Sequence elements"), MB_OK);
}

//VARIANT VT_UI1