97
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 *******************************************************************************/
|
|
11 module dwt.ole.win32.Variant;
|
|
12
|
|
13 import dwt.DWT;
|
|
14 import dwt.DWTException;
|
|
15 import dwt.internal.ole.win32.extras;
|
|
16 import dwt.internal.ole.win32.COM;
|
|
17 import dwt.internal.ole.win32.COMTYPES;
|
|
18 import dwt.internal.ole.win32.OAIDL;
|
|
19 import dwt.internal.win32.OS;
|
|
20
|
|
21 import dwt.ole.win32.OleAutomation;
|
|
22 import dwt.ole.win32.OLE;
|
|
23
|
|
24 import tango.util.Convert;
|
|
25 import tango.text.convert.Format;
|
|
26
|
|
27 /**
|
|
28 *
|
|
29 * A Variant is a generic OLE mechanism for passing data of different types via a common interface.
|
|
30 *
|
|
31 * <p>It is used within the OleAutomation object for getting a property, setting a property or invoking
|
|
32 * a method on an OLE Control or OLE Document.
|
|
33 *
|
|
34 */
|
|
35 public final class Variant
|
|
36 {
|
|
37 /**
|
|
38 * A variant always takes up 16 bytes, no matter what you
|
|
39 * store in it. Objects, strings, and arrays are not physically
|
|
40 * stored in the Variant; in these cases, four bytes of the
|
|
41 * Variant are used to hold either an object reference, or a
|
|
42 * pointer to the string or array. The actual data are stored elsewhere.
|
|
43 */
|
|
44 //public static final int sizeof = 16;
|
|
45 private short type; // OLE.VT_* type
|
|
46
|
|
47 private bool booleanData;
|
|
48 private byte byteData;
|
|
49 private short shortData;
|
|
50 private char charData;
|
|
51 private int intData;
|
|
52 private long longData;
|
|
53 private float floatData;
|
|
54 private double doubleData;
|
|
55 private char[] stringData;
|
|
56 private void* byRefPtr;
|
|
57 private IDispatch dispatchData;
|
|
58 private IUnknown unknownData;
|
|
59
|
|
60 /**
|
|
61 * Invokes platform specific functionality to copy a variant
|
|
62 * into operating system memory.
|
|
63 * <p>
|
|
64 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
|
|
65 * API for <code>Variant</code>. It is marked public only so that it
|
|
66 * can be shared within the packages provided by DWT. It is not
|
|
67 * available on all platforms, and should never be called from
|
|
68 * application code.
|
|
69 * </p>
|
|
70 *
|
|
71 * @param pVarDest destination pointer to a variant
|
|
72 * @param varSrc source <code>Variant</code>
|
|
73 *
|
|
74 * @since 3.3
|
|
75 */
|
|
76 public static void win32_copy (VARIANT* pVarDest, Variant varSrc) {
|
|
77 varSrc.getData (pVarDest);
|
|
78 }
|
|
79
|
|
80 /**
|
|
81 * Invokes platform specific functionality to wrap a variant
|
|
82 * that was allocated in operating system memory.
|
|
83 * <p>
|
|
84 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
|
|
85 * API for <code>Variant</code>. It is marked public only so that it
|
|
86 * can be shared within the packages provided by DWT. It is not
|
|
87 * available on all platforms, and should never be called from
|
|
88 * application code.
|
|
89 * </p>
|
|
90 *
|
|
91 * @param pVariant pointer to a variant
|
|
92 *
|
|
93 * @return a new <code>Variant</code>
|
|
94 *
|
|
95 * @since 3.3
|
|
96 */
|
|
97 public static Variant win32_new (VARIANT* pVariant) {
|
|
98 Variant variant = new Variant ();
|
|
99 variant.setData (pVariant);
|
|
100 return variant;
|
|
101 }
|
|
102
|
|
103 /**
|
|
104 * Create an empty Variant object with type VT_EMPTY.
|
|
105 *
|
|
106 * @since 2.0
|
|
107 */
|
|
108 public this(){
|
|
109 type = COM.VT_EMPTY;
|
|
110 }
|
|
111 /**
|
|
112 * Create a Variant object which represents a Java float as a VT_R4.
|
|
113 *
|
|
114 * @param val the Java float value that this Variant represents
|
|
115 *
|
|
116 */
|
|
117 public this(float val) {
|
|
118 type = COM.VT_R4;
|
|
119 floatData = val;
|
|
120
|
|
121 }
|
|
122 /**
|
|
123 * Create a Variant object which represents a Java double as a VT_R8.
|
|
124 *
|
|
125 * @param val the Java double value that this Variant represents
|
|
126 *
|
|
127 * @since 3.2
|
|
128 */
|
|
129 public this(double val) {
|
|
130 type = COM.VT_R8;
|
|
131 doubleData = val;
|
|
132 }
|
|
133 /**
|
|
134 * Create a Variant object which represents a Java int as a VT_I4.
|
|
135 *
|
|
136 * @param val the Java int value that this Variant represents
|
|
137 *
|
|
138 */
|
|
139 public this(int val) {
|
|
140 type = COM.VT_I4;
|
|
141 intData = val;
|
|
142 }
|
|
143 public this(uint val) {
|
|
144 type = COM.VT_I4;
|
|
145 intData = val;
|
|
146 }
|
|
147 /**
|
|
148 * Create a Variant object which contains a reference to the data being transferred.
|
|
149 *
|
|
150 * <p>When creating a VT_BYREF Variant, you must give the full Variant type
|
|
151 * including VT_BYREF such as
|
|
152 *
|
|
153 * <pre><code>short byRefType = OLE.VT_BSTR | OLE.VT_BYREF</code></pre>.
|
|
154 *
|
|
155 * @param ptr a pointer to the data being transferred.
|
|
156 * @param byRefType the type of the data being transferred such as OLE.VT_BSTR | OLE.VT_BYREF
|
|
157 *
|
|
158 */
|
|
159 public this(void* ptr, ushort byRefType) {
|
|
160 type = byRefType;
|
|
161 byRefPtr = ptr;
|
|
162 }
|
|
163 /**
|
|
164 * Create a Variant object which represents an IDispatch interface as a VT_Dispatch.
|
|
165 *
|
|
166 * @param automation the OleAutomation object that this Variant represents
|
|
167 *
|
|
168 */
|
|
169 public this(OleAutomation automation) {
|
|
170 type = COM.VT_DISPATCH;
|
|
171 dispatchData = automation.getAddress();
|
|
172 }
|
|
173 /**
|
|
174 * Create a Variant object which represents an IDispatch interface as a VT_Dispatch.
|
|
175 * <p>The caller is expected to have appropriately invoked unknown.AddRef() before creating
|
|
176 * this Variant.
|
|
177 *
|
|
178 * @since 2.0
|
|
179 *
|
|
180 * @param idispatch the IDispatch object that this Variant represents
|
|
181 *
|
|
182 */
|
|
183 public this(IDispatch idispatch) {
|
|
184 type = COM.VT_DISPATCH;
|
|
185 dispatchData = idispatch;
|
|
186 }
|
|
187 /**
|
|
188 * Create a Variant object which represents an IUnknown interface as a VT_UNKNOWN.
|
|
189 *
|
|
190 * <p>The caller is expected to have appropriately invoked unknown.AddRef() before creating
|
|
191 * this Variant.
|
|
192 *
|
|
193 * @param unknown the IUnknown object that this Variant represents
|
|
194 *
|
|
195 */
|
|
196 public this(IUnknown unknown) {
|
|
197 type = COM.VT_UNKNOWN;
|
|
198 unknownData = unknown;
|
|
199 }
|
|
200 /**
|
|
201 * Create a Variant object which represents a Java long as a VT_I8.
|
|
202 *
|
|
203 * @param val the Java long value that this Variant represents
|
|
204 *
|
|
205 *@since 3.2
|
|
206 */
|
|
207 public this(long val) {
|
|
208 type = COM.VT_I8;
|
|
209 longData = val;
|
|
210 }
|
|
211 /**
|
|
212 * Create a Variant object which represents a Java String as a VT_BSTR.
|
|
213 *
|
|
214 * @param string the Java String value that this Variant represents
|
|
215 *
|
|
216 */
|
|
217 public this(char[] string) {
|
|
218 type = COM.VT_BSTR;
|
|
219 stringData = string;
|
|
220 }
|
|
221 /**
|
|
222 * Create a Variant object which represents a Java short as a VT_I2.
|
|
223 *
|
|
224 * @param val the Java short value that this Variant represents
|
|
225 *
|
|
226 */
|
|
227 public this(short val) {
|
|
228 type = COM.VT_I2;
|
|
229 shortData = val;
|
|
230 }
|
|
231 /**
|
|
232 * Create a Variant object which represents a Java bool as a VT_BOOL.
|
|
233 *
|
|
234 * @param val the Java bool value that this Variant represents
|
|
235 *
|
|
236 */
|
|
237 public this(bool val) {
|
|
238 type = COM.VT_BOOL;
|
|
239 booleanData = val;
|
|
240 }
|
|
241
|
|
242 /**
|
|
243 * Calling dispose will release resources associated with this Variant.
|
|
244 * If the resource is an IDispatch or IUnknown interface, Release will be called.
|
|
245 * If the resource is a ByRef pointer, nothing is released.
|
|
246 *
|
|
247 * @since 2.1
|
|
248 */
|
|
249 public void dispose() {
|
|
250 if ((type & COM.VT_BYREF) is COM.VT_BYREF) {
|
|
251 return;
|
|
252 }
|
|
253
|
|
254 switch (type) {
|
|
255 case COM.VT_DISPATCH :
|
|
256 dispatchData.Release();
|
|
257 break;
|
|
258 case COM.VT_UNKNOWN :
|
|
259 unknownData.Release();
|
|
260 break;
|
|
261 default:
|
|
262 }
|
|
263
|
|
264 }
|
|
265 /**
|
|
266 * Returns the OleAutomation object represented by this Variant.
|
|
267 *
|
|
268 * <p>If this Variant does not contain an OleAutomation object, an attempt is made to
|
|
269 * coerce the Variant type into an OleAutomation object. If this fails, an error is
|
|
270 * thrown. Note that OleAutomation objects must be disposed when no longer
|
|
271 * needed.
|
|
272 *
|
|
273 * @return the OleAutomation object represented by this Variant
|
|
274 *
|
|
275 * @exception DWTException <ul>
|
|
276 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into an OleAutomation object</li>
|
|
277 * </ul>
|
|
278 */
|
|
279 public OleAutomation getAutomation() {
|
|
280 if (type is COM.VT_EMPTY) {
|
|
281 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
282 }
|
|
283 if (type is COM.VT_DISPATCH) {
|
|
284 return new OleAutomation(dispatchData);
|
|
285 }
|
|
286 // try to coerce the value to the desired type
|
|
287 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
288 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
289 try {
|
|
290 getData(oldPtr);
|
|
291 HRESULT result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_DISPATCH);
|
|
292 if (result !is COM.S_OK)
|
|
293 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
294 Variant autoVar = new Variant();
|
|
295 autoVar.setData(newPtr);
|
|
296 return autoVar.getAutomation();
|
|
297 } finally {
|
|
298 COM.VariantClear(oldPtr);
|
|
299 OS.GlobalFree(oldPtr);
|
|
300 COM.VariantClear(newPtr); // Note: This must absolutely be done AFTER the
|
|
301 // OleAutomation object is created as Variant Clear
|
|
302 // will result in a Release being performed on the
|
|
303 // Dispatch object
|
|
304 OS.GlobalFree(newPtr);
|
|
305 }
|
|
306 }
|
|
307 /**
|
|
308 * Returns the IDispatch object represented by this Variant.
|
|
309 *
|
|
310 * <p>If this Variant does not contain an IDispatch object, an attempt is made to
|
|
311 * coerce the Variant type into an IDIspatch object. If this fails, an error is
|
|
312 * thrown.
|
|
313 *
|
|
314 * @since 2.0
|
|
315 *
|
|
316 * @return the IDispatch object represented by this Variant
|
|
317 *
|
|
318 * @exception DWTException <ul>
|
|
319 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into an IDispatch object</li>
|
|
320 * </ul>
|
|
321 */
|
|
322 public IDispatch getDispatch() {
|
|
323 if (type is COM.VT_EMPTY) {
|
|
324 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
325 }
|
|
326 if (type is COM.VT_DISPATCH) {
|
|
327 return dispatchData;
|
|
328 }
|
|
329 // try to coerce the value to the desired type
|
|
330 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
331 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
332 try {
|
|
333 getData(oldPtr);
|
|
334 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_DISPATCH);
|
|
335 if (result !is COM.S_OK)
|
|
336 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
337 Variant autoVar = new Variant();
|
|
338 autoVar.setData(newPtr);
|
|
339 return autoVar.getDispatch();
|
|
340 } finally {
|
|
341 COM.VariantClear(oldPtr);
|
|
342 OS.GlobalFree(oldPtr);
|
|
343 COM.VariantClear(newPtr); // Note: This must absolutely be done AFTER the
|
|
344 // OleAutomation object is created as Variant Clear
|
|
345 // will result in a Release being performed on the
|
|
346 // Dispatch object
|
|
347 OS.GlobalFree(newPtr);
|
|
348 }
|
|
349 }
|
|
350 /**
|
|
351 * Returns the Java bool represented by this Variant.
|
|
352 *
|
|
353 * <p>If this Variant does not contain a Java bool, an attempt is made to
|
|
354 * coerce the Variant type into a Java bool. If this fails, an error is thrown.
|
|
355 *
|
|
356 * @return the Java bool represented by this Variant
|
|
357 *
|
|
358 * @exception DWTException <ul>
|
|
359 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a bool</li>
|
|
360 * </ul>
|
|
361 *
|
|
362 */
|
|
363 public bool getBoolean() {
|
|
364 if (type is COM.VT_EMPTY) {
|
|
365 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
366 }
|
|
367 if (type is COM.VT_BOOL) {
|
|
368 return booleanData;
|
|
369 }
|
|
370
|
|
371 // try to coerce the value to the desired type
|
|
372 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
373 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
374 try {
|
|
375 getData(oldPtr);
|
|
376 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_BOOL);
|
|
377 if (result !is COM.S_OK)
|
|
378 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
379 Variant boolVar = new Variant();
|
|
380 boolVar.setData(newPtr);
|
|
381 return boolVar.getBoolean();
|
|
382 } finally {
|
|
383 COM.VariantClear(oldPtr);
|
|
384 OS.GlobalFree(oldPtr);
|
|
385 COM.VariantClear(newPtr);
|
|
386 OS.GlobalFree(newPtr);
|
|
387 }
|
|
388 }
|
|
389 /**
|
|
390 * Returns a pointer to the referenced data represented by this Variant.
|
|
391 *
|
|
392 * <p>If this Variant does not contain a reference to data, zero is returned.
|
|
393 *
|
|
394 * @return a pointer to the referenced data represented by this Variant or 0
|
|
395 *
|
|
396 */
|
|
397 public void* getByRef() {
|
|
398 if (type is COM.VT_EMPTY) {
|
|
399 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
400 }
|
|
401 if ((type & COM.VT_BYREF)is COM.VT_BYREF) {
|
|
402 return byRefPtr;
|
|
403 }
|
|
404
|
|
405 return null;
|
|
406 }
|
|
407 /**
|
|
408 * Returns the Java byte represented by this Variant.
|
|
409 *
|
|
410 * <p>If this Variant does not contain a Java byte, an attempt is made to
|
|
411 * coerce the Variant type into a Java byte. If this fails, an error is thrown.
|
|
412 *
|
|
413 * @return the Java byte represented by this Variant
|
|
414 *
|
|
415 * @exception DWTException <ul>
|
|
416 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a byte</li>
|
|
417 * </ul>
|
|
418 *
|
|
419 * @since 3.3
|
|
420 */
|
|
421 public byte getByte() {
|
|
422 if (type is COM.VT_EMPTY) {
|
|
423 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
424 }
|
|
425 if (type is COM.VT_I1) {
|
|
426 return byteData;
|
|
427 }
|
|
428
|
|
429 // try to coerce the value to the desired type
|
|
430 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
431 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
432 try {
|
|
433 getData(oldPtr);
|
|
434 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_I1);
|
|
435 if (result !is COM.S_OK)
|
|
436 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
437 Variant byteVar = new Variant();
|
|
438 byteVar.setData(newPtr);
|
|
439 return byteVar.getByte();
|
|
440 } finally {
|
|
441 COM.VariantClear(oldPtr);
|
|
442 OS.GlobalFree(oldPtr);
|
|
443 COM.VariantClear(newPtr);
|
|
444 OS.GlobalFree(newPtr);
|
|
445 }
|
|
446 }
|
|
447 /**
|
|
448 * Returns the Java char represented by this Variant.
|
|
449 *
|
|
450 * <p>If this Variant does not contain a Java char, an attempt is made to
|
|
451 * coerce the Variant type into a Java char. If this fails, an error is thrown.
|
|
452 *
|
|
453 * @return the Java char represented by this Variant
|
|
454 *
|
|
455 * @exception DWTException <ul>
|
|
456 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a char</li>
|
|
457 * </ul>
|
|
458 *
|
|
459 * @since 3.3
|
|
460 */
|
|
461 public char getChar() {
|
|
462 if (type is COM.VT_EMPTY) {
|
|
463 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
464 }
|
|
465 if (type is COM.VT_UI2) {
|
|
466 return charData;
|
|
467 }
|
|
468
|
|
469 // try to coerce the value to the desired type
|
|
470 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
471 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
472 try {
|
|
473 getData(oldPtr);
|
|
474 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_UI2);
|
|
475 if (result !is COM.S_OK)
|
|
476 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
477 Variant charVar = new Variant();
|
|
478 charVar.setData(newPtr);
|
|
479 return charVar.getChar();
|
|
480 } finally {
|
|
481 COM.VariantClear(oldPtr);
|
|
482 OS.GlobalFree(oldPtr);
|
|
483 COM.VariantClear(newPtr);
|
|
484 OS.GlobalFree(newPtr);
|
|
485 }
|
|
486 }
|
|
487 void getData(VARIANT* pData){
|
|
488 if (pData is null) OLE.error(OLE.ERROR_OUT_OF_MEMORY);
|
|
489
|
|
490 COM.VariantInit(pData);
|
|
491
|
|
492 // set type
|
|
493 pData.vt = type;
|
|
494 if ((type & COM.VT_BYREF) is COM.VT_BYREF) {
|
|
495 COM.MoveMemory(pData, &type, 2);
|
|
496 COM.MoveMemory(pData + 8, &byRefPtr, 4);
|
|
497 return;
|
|
498 }
|
|
499
|
|
500 switch (type) {
|
|
501 case COM.VT_EMPTY :
|
|
502 case COM.VT_NULL :
|
|
503 COM.MoveMemory(pData, &type, 2);
|
|
504 break;
|
|
505 case COM.VT_BOOL :
|
|
506 COM.MoveMemory(pData, &type, 2);
|
|
507 auto v = booleanData ? COM.VARIANT_TRUE : COM.VARIANT_FALSE;
|
|
508 COM.MoveMemory(pData + 8, &v, 2);
|
|
509 break;
|
|
510 case COM.VT_I1 :
|
|
511 COM.MoveMemory(pData, &type, 2);
|
|
512 COM.MoveMemory(pData + 8, &byteData, 1);
|
|
513 break;
|
|
514 case COM.VT_I2 :
|
|
515 COM.MoveMemory(pData, &type, 2);
|
|
516 COM.MoveMemory(pData + 8, &shortData, 2);
|
|
517 break;
|
|
518 case COM.VT_UI2 :
|
|
519 COM.MoveMemory(pData, &type, 2);
|
|
520 COM.MoveMemory(pData + 8, &charData, 2);
|
|
521 break;
|
|
522 case COM.VT_I4 :
|
|
523 COM.MoveMemory(pData, &type, 2);
|
|
524 COM.MoveMemory(pData + 8, &intData, 4);
|
|
525 break;
|
|
526 case COM.VT_I8 :
|
|
527 COM.MoveMemory(pData, &type, 2);
|
|
528 COM.MoveMemory(pData + 8, &longData, 8);
|
|
529 break;
|
|
530 case COM.VT_R4 :
|
|
531 COM.MoveMemory(pData, &type, 2);
|
|
532 COM.MoveMemory(pData + 8, &floatData, 4);
|
|
533 break;
|
|
534 case COM.VT_R8 :
|
|
535 COM.MoveMemory(pData, &type, 2);
|
|
536 COM.MoveMemory(pData + 8, &doubleData, 8);
|
|
537 break;
|
|
538 case COM.VT_DISPATCH :
|
|
539 dispatchData.AddRef();
|
|
540 COM.MoveMemory(pData, &type, 2);
|
|
541 auto v = cast(void*)dispatchData;
|
|
542 COM.MoveMemory(pData + 8, &v, 4);
|
|
543 break;
|
|
544 case COM.VT_UNKNOWN :
|
|
545 unknownData.AddRef();
|
|
546 COM.MoveMemory(pData, &type, 2);
|
|
547 auto v = cast(void*)dispatchData;
|
|
548 COM.MoveMemory(pData + 8, &v, 4);
|
|
549 break;
|
|
550 case COM.VT_BSTR :
|
|
551 COM.MoveMemory(pData, &type, 2);
|
|
552 wchar[] data = StrToWCHARs(stringData);
|
|
553 auto ptr = COM.SysAllocString(data.ptr);
|
|
554 COM.MoveMemory(pData + 8, &ptr, 4);
|
|
555 break;
|
|
556
|
|
557 default :
|
|
558 OLE.error(DWT.ERROR_NOT_IMPLEMENTED);
|
|
559 }
|
|
560 }
|
|
561 /**
|
|
562 * Returns the Java double represented by this Variant.
|
|
563 *
|
|
564 * <p>If this Variant does not contain a Java double, an attempt is made to
|
|
565 * coerce the Variant type into a Java double. If this fails, an error is thrown.
|
|
566 *
|
|
567 * @return the Java double represented by this Variant
|
|
568 *
|
|
569 * @exception DWTException <ul>
|
|
570 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a double</li>
|
|
571 * </ul>
|
|
572 *
|
|
573 * @since 3.2
|
|
574 */
|
|
575 public double getDouble() {
|
|
576 if (type is COM.VT_EMPTY) {
|
|
577 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
578 }
|
|
579 if (type is COM.VT_R8) {
|
|
580 return doubleData;
|
|
581 }
|
|
582
|
|
583 // try to coerce the value to the desired type
|
|
584 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
585 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
586 try {
|
|
587 getData(oldPtr);
|
|
588 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_R8);
|
|
589 if (result !is COM.S_OK)
|
|
590 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
591 Variant doubleVar = new Variant();
|
|
592 doubleVar.setData(newPtr);
|
|
593 return doubleVar.getDouble();
|
|
594 } finally {
|
|
595 COM.VariantClear(oldPtr);
|
|
596 OS.GlobalFree(oldPtr);
|
|
597 COM.VariantClear(newPtr);
|
|
598 OS.GlobalFree(newPtr);
|
|
599 }
|
|
600 }
|
|
601
|
|
602 /**
|
|
603 * Returns the Java float represented by this Variant.
|
|
604 *
|
|
605 * <p>If this Variant does not contain a Java float, an attempt is made to
|
|
606 * coerce the Variant type into a Java float. If this fails, an error is thrown.
|
|
607 *
|
|
608 * @return the Java float represented by this Variant
|
|
609 *
|
|
610 * @exception DWTException <ul>
|
|
611 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a float</li>
|
|
612 * </ul>
|
|
613 */
|
|
614 public float getFloat() {
|
|
615 if (type is COM.VT_EMPTY) {
|
|
616 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
617 }
|
|
618 if (type is COM.VT_R4) {
|
|
619 return floatData;
|
|
620 }
|
|
621
|
|
622 // try to coerce the value to the desired type
|
|
623 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
624 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
625 try {
|
|
626 getData(oldPtr);
|
|
627 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_R4);
|
|
628 if (result !is COM.S_OK)
|
|
629 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
630 Variant floatVar = new Variant();
|
|
631 floatVar.setData(newPtr);
|
|
632 return floatVar.getFloat();
|
|
633 } finally {
|
|
634 COM.VariantClear(oldPtr);
|
|
635 OS.GlobalFree(oldPtr);
|
|
636 COM.VariantClear(newPtr);
|
|
637 OS.GlobalFree(newPtr);
|
|
638 }
|
|
639
|
|
640 }
|
|
641 /**
|
|
642 * Returns the Java int represented by this Variant.
|
|
643 *
|
|
644 * <p>If this Variant does not contain a Java int, an attempt is made to
|
|
645 * coerce the Variant type into a Java int. If this fails, an error is thrown.
|
|
646 *
|
|
647 * @return the Java int represented by this Variant
|
|
648 *
|
|
649 * @exception DWTException <ul>
|
|
650 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a int</li>
|
|
651 * </ul>
|
|
652 */
|
|
653 public int getInt() {
|
|
654 if (type is COM.VT_EMPTY) {
|
|
655 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
656 }
|
|
657 if (type is COM.VT_I4) {
|
|
658 return intData;
|
|
659 }
|
|
660
|
|
661 // try to coerce the value to the desired type
|
|
662 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
663 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
664 try {
|
|
665 getData(oldPtr);
|
|
666 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_I4);
|
|
667 if (result !is COM.S_OK)
|
|
668 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
669 Variant intVar = new Variant();
|
|
670 intVar.setData(newPtr);
|
|
671 return intVar.getInt();
|
|
672 } finally {
|
|
673 COM.VariantClear(oldPtr);
|
|
674 OS.GlobalFree(oldPtr);
|
|
675 COM.VariantClear(newPtr);
|
|
676 OS.GlobalFree(newPtr);
|
|
677 }
|
|
678 }
|
|
679 /**
|
|
680 * Returns the Java long represented by this Variant.
|
|
681 *
|
|
682 * <p>If this Variant does not contain a Java long, an attempt is made to
|
|
683 * coerce the Variant type into a Java long. If this fails, an error is thrown.
|
|
684 *
|
|
685 * @return the Java long represented by this Variant
|
|
686 *
|
|
687 * @exception DWTException <ul>
|
|
688 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a long</li>
|
|
689 * </ul>
|
|
690 *
|
|
691 * @since 3.2
|
|
692 */
|
|
693 public long getLong() {
|
|
694 if (type is COM.VT_EMPTY) {
|
|
695 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
696 }
|
|
697 if (type is COM.VT_I8) {
|
|
698 return longData;
|
|
699 }
|
|
700
|
|
701 // try to coerce the value to the desired type
|
|
702 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
703 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
704 try {
|
|
705 getData(oldPtr);
|
|
706 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_I8);
|
|
707 if (result !is COM.S_OK)
|
|
708 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
709 Variant longVar = new Variant();
|
|
710 longVar.setData(newPtr);
|
|
711 return longVar.getLong();
|
|
712 } finally {
|
|
713 COM.VariantClear(oldPtr);
|
|
714 OS.GlobalFree(oldPtr);
|
|
715 COM.VariantClear(newPtr);
|
|
716 OS.GlobalFree(newPtr);
|
|
717 }
|
|
718 }
|
|
719 /**
|
|
720 * Returns the Java short represented by this Variant.
|
|
721 *
|
|
722 * <p>If this Variant does not contain a Java short, an attempt is made to
|
|
723 * coerce the Variant type into a Java short. If this fails, an error is thrown.
|
|
724 *
|
|
725 * @return the Java short represented by this Variant
|
|
726 *
|
|
727 * @exception DWTException <ul>
|
|
728 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a short</li>
|
|
729 * </ul>
|
|
730 */
|
|
731 public short getShort() {
|
|
732 if (type is COM.VT_EMPTY) {
|
|
733 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
734 }
|
|
735 if (type is COM.VT_I2) {
|
|
736 return shortData;
|
|
737 }
|
|
738
|
|
739 // try to coerce the value to the desired type
|
|
740 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
741 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
742 try {
|
|
743 getData(oldPtr);
|
|
744 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_I2);
|
|
745 if (result !is COM.S_OK)
|
|
746 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
747 Variant shortVar = new Variant();
|
|
748 shortVar.setData(newPtr);
|
|
749 return shortVar.getShort();
|
|
750 } finally {
|
|
751 COM.VariantClear(oldPtr);
|
|
752 OS.GlobalFree(oldPtr);
|
|
753 COM.VariantClear(newPtr);
|
|
754 OS.GlobalFree(newPtr);
|
|
755 }
|
|
756
|
|
757 }
|
|
758 /**
|
|
759 * Returns the Java String represented by this Variant.
|
|
760 *
|
|
761 * <p>If this Variant does not contain a Java String, an attempt is made to
|
|
762 * coerce the Variant type into a Java String. If this fails, an error is thrown.
|
|
763 *
|
|
764 * @return the Java String represented by this Variant
|
|
765 *
|
|
766 * @exception DWTException <ul>
|
|
767 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into a String</li>
|
|
768 * </ul>
|
|
769 */
|
|
770 public char[] getString() {
|
|
771 if (type is COM.VT_EMPTY) {
|
|
772 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
773 }
|
|
774 if (type is COM.VT_BSTR) {
|
|
775 return stringData;
|
|
776 }
|
|
777
|
|
778 // try to coerce the value to the desired type
|
|
779 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
780 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
781 try {
|
|
782 getData(oldPtr);
|
|
783 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_BSTR);
|
|
784 if (result !is COM.S_OK)
|
|
785 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
786
|
|
787 Variant stringVar = new Variant();
|
|
788 stringVar.setData(newPtr);
|
|
789 return stringVar.getString();
|
|
790
|
|
791 } finally {
|
|
792 COM.VariantClear(oldPtr);
|
|
793 OS.GlobalFree(oldPtr);
|
|
794 COM.VariantClear(newPtr);
|
|
795 OS.GlobalFree(newPtr);
|
|
796 }
|
|
797 }
|
|
798 /**
|
|
799 * Returns the type of the variant type. This will be an OLE.VT_* value or
|
|
800 * a bitwise combination of OLE.VT_* values as in the case of
|
|
801 * OLE.VT_BSTR | OLE.VT_BYREF.
|
|
802 *
|
|
803 * @return the type of the variant data
|
|
804 *
|
|
805 * @since 2.0
|
|
806 */
|
|
807 public short getType() {
|
|
808 return type;
|
|
809 }
|
|
810 /**
|
|
811 * Returns the IUnknown object represented by this Variant.
|
|
812 *
|
|
813 * <p>If this Variant does not contain an IUnknown object, an attempt is made to
|
|
814 * coerce the Variant type into an IUnknown object. If this fails, an error is
|
|
815 * thrown.
|
|
816 *
|
|
817 * @return the IUnknown object represented by this Variant
|
|
818 *
|
|
819 * @exception DWTException <ul>
|
|
820 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant can not be coerced into
|
|
821 * an IUnknown object</li>
|
|
822 * </ul>
|
|
823 */
|
|
824 public IUnknown getUnknown() {
|
|
825 if (type is COM.VT_EMPTY) {
|
|
826 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1);
|
|
827 }
|
|
828 if (type is COM.VT_UNKNOWN) {
|
|
829 return unknownData;
|
|
830 }
|
|
831
|
|
832 // try to coerce the value to the desired type
|
|
833 auto oldPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
834 auto newPtr = cast(VARIANT*) OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
835 try {
|
|
836 getData(oldPtr);
|
|
837 int result = COM.VariantChangeType(newPtr, oldPtr, 0, COM.VT_UNKNOWN);
|
|
838 if (result !is COM.S_OK)
|
|
839 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result);
|
|
840 Variant unknownVar = new Variant();
|
|
841 unknownVar.setData(newPtr);
|
|
842 return unknownVar.getUnknown();
|
|
843 } finally {
|
|
844 COM.VariantClear(oldPtr);
|
|
845 OS.GlobalFree(oldPtr);
|
|
846 COM.VariantClear(newPtr); // Note: This must absolutely be done AFTER the
|
|
847 // IUnknown object is created as Variant Clear
|
|
848 // will result in a Release being performed on the
|
|
849 // Dispatch object
|
|
850 OS.GlobalFree(newPtr);
|
|
851 }
|
|
852 }
|
|
853 /**
|
|
854 * Update the by reference value of this variant with a new bool value.
|
|
855 *
|
|
856 * @param val the new bool value
|
|
857 *
|
|
858 * @exception DWTException <ul>
|
|
859 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant is not
|
|
860 * a (VT_BYREF | VT_BOOL) object</li>
|
|
861 * </ul>
|
|
862 *
|
|
863 * @since 2.1
|
|
864 */
|
|
865 public void setByRef(bool val) {
|
|
866 if ((type & COM.VT_BYREF) is 0 || (type & COM.VT_BOOL) is 0) {
|
|
867 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE);
|
|
868 }
|
|
869 auto v = val ? COM.VARIANT_TRUE : COM.VARIANT_FALSE;
|
|
870 COM.MoveMemory(byRefPtr, &v, 2);
|
|
871 }
|
|
872 /**
|
|
873 * Update the by reference value of this variant with a new float value.
|
|
874 *
|
|
875 * @param val the new float value
|
|
876 *
|
|
877 * @exception DWTException <ul>
|
|
878 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant is not
|
|
879 * a (VT_BYREF | VT_R4) object</li>
|
|
880 * </ul>
|
|
881 *
|
|
882 * @since 2.1
|
|
883 */
|
|
884 public void setByRef(float val) {
|
|
885 if ((type & COM.VT_BYREF) is 0 || (type & COM.VT_R4) is 0) {
|
|
886 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE);
|
|
887 }
|
|
888 COM.MoveMemory(byRefPtr, &val, 4);
|
|
889 }
|
|
890 /**
|
|
891 * Update the by reference value of this variant with a new integer value.
|
|
892 *
|
|
893 * @param val the new integer value
|
|
894 *
|
|
895 * @exception DWTException <ul>
|
|
896 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant is not a (VT_BYREF | VT_I4) object</li>
|
|
897 * </ul>
|
|
898 *
|
|
899 * @since 2.1
|
|
900 */
|
|
901 public void setByRef(int val) {
|
|
902 if ((type & COM.VT_BYREF) is 0 || (type & COM.VT_I4) is 0) {
|
|
903 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE);
|
|
904 }
|
|
905 COM.MoveMemory(byRefPtr, &val, 4);
|
|
906 }
|
|
907 /**
|
|
908 * Update the by reference value of this variant with a new short value.
|
|
909 *
|
|
910 * @param val the new short value
|
|
911 *
|
|
912 * @exception DWTException <ul>
|
|
913 * <li>ERROR_CANNOT_CHANGE_VARIANT_TYPE when type of Variant is not a (VT_BYREF | VT_I2) object
|
|
914 * </ul>
|
|
915 *
|
|
916 * @since 2.1
|
|
917 */
|
|
918 public void setByRef(short val) {
|
|
919 if ((type & COM.VT_BYREF) is 0 || (type & COM.VT_I2) is 0) {
|
|
920 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE);
|
|
921 }
|
|
922 COM.MoveMemory(byRefPtr, &val, 2);
|
|
923 }
|
|
924
|
|
925 void setData(VARIANT* pData){
|
|
926 if (pData is null) OLE.error(OLE.ERROR_INVALID_ARGUMENT);
|
|
927
|
|
928 short[1] dataType ;
|
|
929 COM.MoveMemory(dataType.ptr, pData, 2);
|
|
930 type = dataType[0];
|
|
931
|
|
932 if ((type & COM.VT_BYREF) is COM.VT_BYREF) {
|
|
933 void*[1] newByRefPtr;
|
|
934 OS.MoveMemory(newByRefPtr.ptr, pData + 8, 4);
|
|
935 byRefPtr = newByRefPtr[0];
|
|
936 return;
|
|
937 }
|
|
938
|
|
939 switch (type) {
|
|
940 case COM.VT_EMPTY :
|
|
941 case COM.VT_NULL :
|
|
942 break;
|
|
943 case COM.VT_BOOL :
|
|
944 short[1] newBooleanData;
|
|
945 COM.MoveMemory(newBooleanData.ptr, pData + 8, 2);
|
|
946 booleanData = (newBooleanData[0] !is COM.VARIANT_FALSE);
|
|
947 break;
|
|
948 case COM.VT_I1 :
|
|
949 byte[1] newByteData;
|
|
950 COM.MoveMemory(newByteData.ptr, pData + 8, 1);
|
|
951 byteData = newByteData[0];
|
|
952 break;
|
|
953 case COM.VT_I2 :
|
|
954 short[1] newShortData;
|
|
955 COM.MoveMemory(newShortData.ptr, pData + 8, 2);
|
|
956 shortData = newShortData[0];
|
|
957 break;
|
|
958 case COM.VT_UI2 :
|
|
959 char[1] newCharData;
|
|
960 COM.MoveMemory(newCharData.ptr, pData + 8, 2);
|
|
961 charData = newCharData[0];
|
|
962 break;
|
|
963 case COM.VT_I4 :
|
|
964 int[1] newIntData;
|
|
965 OS.MoveMemory(newIntData.ptr, pData + 8, 4);
|
|
966 intData = newIntData[0];
|
|
967 break;
|
|
968 case COM.VT_I8 :
|
|
969 long[1] newLongData;
|
|
970 OS.MoveMemory(newLongData.ptr, pData + 8, 8);
|
|
971 longData = newLongData[0];
|
|
972 break;
|
|
973 case COM.VT_R4 :
|
|
974 float[1] newFloatData;
|
|
975 COM.MoveMemory(newFloatData.ptr, pData + 8, 4);
|
|
976 floatData = newFloatData[0];
|
|
977 break;
|
|
978 case COM.VT_R8 :
|
|
979 double[1] newDoubleData;
|
|
980 COM.MoveMemory(newDoubleData.ptr, pData + 8, 8);
|
|
981 doubleData = newDoubleData[0];
|
|
982 break;
|
|
983 case COM.VT_DISPATCH : {
|
|
984 IDispatch[1] ppvObject;
|
|
985 OS.MoveMemory(ppvObject.ptr, pData + 8, 4);
|
|
986 if (ppvObject[0] is null) {
|
|
987 type = COM.VT_EMPTY;
|
|
988 break;
|
|
989 }
|
|
990 dispatchData = ppvObject[0];
|
|
991 dispatchData.AddRef();
|
|
992 break;
|
|
993 }
|
|
994 case COM.VT_UNKNOWN : {
|
|
995 IUnknown[1] ppvObject;
|
|
996 OS.MoveMemory(ppvObject.ptr, pData + 8, 4);
|
|
997 if (ppvObject[0] is null) {
|
|
998 type = COM.VT_EMPTY;
|
|
999 break;
|
|
1000 }
|
|
1001 unknownData = ppvObject[0];
|
|
1002 unknownData.AddRef();
|
|
1003 break;
|
|
1004 }
|
|
1005 case COM.VT_BSTR :
|
|
1006 // get the address of the memory in which the string resides
|
|
1007 wchar*[1] hMem;
|
|
1008 OS.MoveMemory(hMem.ptr, pData + 8, 4);
|
|
1009 if (hMem[0] is null) {
|
|
1010 type = COM.VT_EMPTY;
|
|
1011 break;
|
|
1012 }
|
|
1013 // Get the size of the string from the OS - the size is expressed in number
|
|
1014 // of bytes - each unicode character is 2 bytes.
|
|
1015 int size = COM.SysStringByteLen(hMem[0]);
|
|
1016 if (size > 0){
|
|
1017 // get the unicode character array from the global memory and create a String
|
|
1018 wchar[] buffer = new wchar[(size + 1) /2]; // add one to avoid rounding errors
|
|
1019 COM.MoveMemory(buffer.ptr, hMem[0], size);
|
|
1020 stringData = WCHARsToStr( buffer );
|
|
1021 } else {
|
|
1022 stringData = ""; //$NON-NLS-1$
|
|
1023 }
|
|
1024 break;
|
|
1025
|
|
1026 default :
|
|
1027 // try coercing it into one of the known forms
|
|
1028 auto newPData = cast(VARIANT*) OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, VARIANT.sizeof);
|
|
1029 if (COM.VariantChangeType(newPData, pData, 0, COM.VT_R4) is COM.S_OK) {
|
|
1030 setData(newPData);
|
|
1031 } else if (COM.VariantChangeType(newPData, pData, 0, COM.VT_I4) is COM.S_OK) {
|
|
1032 setData(newPData);
|
|
1033 } else if (COM.VariantChangeType(newPData, pData, 0, COM.VT_BSTR) is COM.S_OK) {
|
|
1034 setData(newPData);
|
|
1035 }
|
|
1036 COM.VariantClear(newPData);
|
|
1037 OS.GlobalFree(newPData);
|
|
1038 break;
|
|
1039 }
|
|
1040 }
|
|
1041
|
|
1042 /**
|
|
1043 * Returns a string containing a concise, human-readable
|
|
1044 * description of the receiver.
|
|
1045 *
|
|
1046 * @return a string representation of the Variant
|
|
1047 */
|
|
1048 public char[] toString () {
|
|
1049 switch (type) {
|
|
1050 case COM.VT_BOOL :
|
|
1051 return "VT_BOOL{"~to!(char[])(booleanData)~"}";
|
|
1052 case COM.VT_I1 :
|
|
1053 return "VT_I1{"~to!(char[])(byteData)~"}";
|
|
1054 case COM.VT_I2 :
|
|
1055 return "VT_I2{"~to!(char[])(shortData)~"}";
|
|
1056 case COM.VT_UI2 :
|
|
1057 return "VT_UI2{"~charData~"}";
|
|
1058 case COM.VT_I4 :
|
|
1059 return "VT_I4{"~to!(char[])(intData)~"}";
|
|
1060 case COM.VT_I8 :
|
|
1061 return "VT_I8{"~to!(char[])(longData)~"}";
|
|
1062 case COM.VT_R4 :
|
|
1063 return "VT_R4{"~to!(char[])(floatData)~"}";
|
|
1064 case COM.VT_R8 :
|
|
1065 return "VT_R8{"~to!(char[])(doubleData)~"}";
|
|
1066 case COM.VT_BSTR :
|
|
1067 return "VT_BSTR{"~stringData~"}";
|
|
1068 case COM.VT_DISPATCH :
|
|
1069 return Format("VT_DISPATCH{{0x{:X}}", cast(void*) (dispatchData is null ? null : dispatchData));
|
|
1070 case COM.VT_UNKNOWN :
|
|
1071 return Format("VT_UNKNOWN{{0x{:X}}", cast(void*) (unknownData is null ? null : unknownData));
|
|
1072 case COM.VT_EMPTY :
|
|
1073 return "VT_EMPTY";
|
|
1074 case COM.VT_NULL :
|
|
1075 return "VT_NULL";
|
|
1076 }
|
|
1077 if ((type & COM.VT_BYREF) !is 0) {
|
|
1078 return Format("VT_BYREF|{}{{{}}",(type & ~COM.VT_BYREF), byRefPtr );
|
|
1079 }
|
|
1080 return "Unsupported Type "~to!(char[])(type);
|
|
1081 }
|
|
1082 }
|