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