1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #pragma warning(disable: 4917)
22 #if !defined WIN32_LEAN_AND_MEAN
23 # define WIN32_LEAN_AND_MEAN
30 #include <com/sun/star/bridge/ModelDependent.hpp>
31 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <oletest/XCallback.hpp>
34 #include <rtl/process.h>
35 #include <cppuhelper/servicefactory.hxx>
36 #include <rtl/string.h>
39 using namespace com::sun::star::lang
;
40 using namespace com::sun::star::uno
;
41 using namespace com::sun::star::bridge
;
42 using namespace com::sun::star::bridge::ModelDependent
;
46 bool incrementMultidimensionalIndex(
48 const sal_Int32
* parDimensionLengths
,
49 sal_Int32
* parMultidimensionalIndex
);
51 int SAL_CALL
main( int /*argc*/, char** /*argv*/ )
54 if( FAILED( hr
=CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
)))
56 printf("CoInitializeEx failed \n");
61 if( FAILED(hr
=doTest()))
64 const CHAR
* errMsg
= err
.ErrorMessage();
65 MessageBoxA( NULL
, errMsg
, "Test failed", MB_ICONERROR
);
78 CComDispatchDriver disp
;
81 CComPtr
<IUnknown
> spUnkFactory
;
82 if( SUCCEEDED( spUnkFactory
.CoCreateInstance(L
"com.sun.star.ServiceManager")))
85 param1
= L
"oletest.OleTest";
86 disp
.Invoke1( L
"createInstance", ¶m1
, &result
);
88 disp
= result
.pdispVal
;
90 // disp contains now oletest.OleTest
92 // one dimensional array
93 par
= SafeArrayCreateVector( VT_UI1
, 0, 5);
94 unsigned char arbyte
[]= { 1,2,3,4,5};
95 for(long i
= 0; i
< 5;i
++)
96 hr
= SafeArrayPutElement( par
, &i
, &arbyte
[i
]);
99 param1
.vt
= VT_ARRAY
| VT_UI1
;
101 disp
.Invoke1(L
"methodByte", ¶m1
, &result
);
102 SafeArrayDestroy( par
);
105 // two dimensional array
106 SAFEARRAYBOUND bounds
[2];
107 // least significant dimension first, Dimension 1
108 bounds
[0].cElements
= 3;
109 bounds
[0].lLbound
= 0;
111 bounds
[1].cElements
= 2;
112 bounds
[1].lLbound
= 0;
113 par
= SafeArrayCreate( VT_I4
, 2, bounds
);
117 hr
= SafeArrayGetUBound( par
, 1, &uBound1
);
118 hr
= SafeArrayGetUBound( par
, 2, &uBound2
);
121 memset( index2
, 0, 2 * sizeof( long) );
122 long dimLengths
[]={3,2};
127 data
= index2
[1] * 3 + index2
[0] +1;
128 hr
= SafeArrayPutElement( par
, index2
, &data
);
129 }while( incrementMultidimensionalIndex( 2, dimLengths
, index2
) );
133 hr
= SafeArrayAccessData( par
, (void**)&pdata
);
134 dataL
= (long(*)[2][3])pdata
;
136 for (long i
= 0; i
< 2; i
++)
138 for(long j
= 0; j
< 3; j
++)
139 data
= (*dataL
)[i
][j
];
141 hr
= SafeArrayUnaccessData(par
);
144 param1
.vt
= VT_ARRAY
| VT_I4
;
146 disp
.Invoke1(L
"methodSequence", ¶m1
, &result
);
148 SAFEARRAY
* arRet
= result
.parray
;
150 for(long i
= 0; i
< 2 ; i
++)
154 hr
= SafeArrayGetElement( arRet
, &i
, &varx
);
155 SAFEARRAY
* ari
= varx
.parray
;
157 for( j
= 0; j
< 3; j
++)
161 hr
= SafeArrayGetElement( ari
, &j
, &varj
);
166 SafeArrayDestroy( par
);
172 // left index is least significant
173 bool incrementMultidimensionalIndex(
174 sal_Int32 dimensions
,
175 const sal_Int32
* parDimensionLengths
,
176 sal_Int32
* parMultidimensionalIndex
)
182 bool carry
= sal_True
; // to get into the while loop
184 sal_Int32 currentDimension
= 0; //most significant is 1
187 parMultidimensionalIndex
[ currentDimension
]++;
188 // if carryover, set index to 0 and handle carry on a level above
189 if( parMultidimensionalIndex
[ currentDimension
] > (parDimensionLengths
[ currentDimension
] - 1))
190 parMultidimensionalIndex
[ currentDimension
]= 0;
195 // if dimensions drops below 1 and carry is set than then all indices are 0 again
196 // this is signalled by returning sal_False
197 if( currentDimension
> dimensions
- 1 && carry
)
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */