1 11 package org.eclipse.swt.ole.win32; 13 14 import org.eclipse.swt.*; 15 import org.eclipse.swt.internal.ole.win32.*; 16 import org.eclipse.swt.internal.win32.*; 17 25 public final class Variant 26 { 27 34 public static final int sizeof = 16; 35 private short type; 37 private boolean booleanData; 38 private byte byteData; 39 private char charData; 40 private double doubleData; 41 private int intData; 42 private float floatData; 43 private long longData; 44 private short shortData; 45 private String stringData; 46 private int byRefPtr; 47 private IDispatch dispatchData; 48 private IUnknown unknownData; 49 50 51 67 public static Variant win32_new (int pVariant) { 68 Variant variant = new Variant (); 69 variant.setData (pVariant); 70 return variant; 71 } 72 73 89 public static void win32_copy (int pVarDest, Variant varSrc) { 90 varSrc.getData (pVarDest); 91 } 92 93 98 public Variant(){ 99 type = COM.VT_EMPTY; 100 } 101 107 public Variant(float val) { 108 type = COM.VT_R4; 109 floatData = val; 110 111 } 112 119 public Variant(double val) { 120 type = COM.VT_R8; 121 doubleData = val; 122 } 123 129 public Variant(int val) { 130 type = COM.VT_I4; 131 intData = val; 132 } 133 145 public Variant(int ptr, short byRefType) { 146 type = byRefType; 147 byRefPtr = ptr; 148 } 149 155 public Variant(OleAutomation automation) { 156 type = COM.VT_DISPATCH; 157 dispatchData = new IDispatch(automation.getAddress()); 158 } 159 169 public Variant(IDispatch idispatch) { 170 type = COM.VT_DISPATCH; 171 dispatchData = idispatch; 172 } 173 182 public Variant(IUnknown unknown) { 183 type = COM.VT_UNKNOWN; 184 unknownData = unknown; 185 } 186 193 public Variant(long val) { 194 type = COM.VT_I8; 195 longData = val; 196 } 197 203 public Variant(String string) { 204 type = COM.VT_BSTR; 205 stringData = string; 206 } 207 213 public Variant(short val) { 214 type = COM.VT_I2; 215 shortData = val; 216 } 217 223 public Variant(boolean val) { 224 type = COM.VT_BOOL; 225 booleanData = val; 226 } 227 228 235 public void dispose() { 236 if ((type & COM.VT_BYREF) == COM.VT_BYREF) { 237 return; 238 } 239 240 switch (type) { 241 case COM.VT_DISPATCH : 242 dispatchData.Release(); 243 break; 244 case COM.VT_UNKNOWN : 245 unknownData.Release(); 246 break; 247 } 248 249 } 250 264 public OleAutomation getAutomation() { 265 if (type == COM.VT_EMPTY) { 266 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 267 } 268 if (type == COM.VT_DISPATCH) { 269 return new OleAutomation(dispatchData); 270 } 271 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 273 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 274 Variant autoVar = null; try { 276 getData(oldPtr); 277 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_DISPATCH); 278 if (result != COM.S_OK) 279 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 280 autoVar = new Variant(); 281 autoVar.setData(newPtr); 282 return autoVar.getAutomation(); 283 } finally { 284 COM.VariantClear(oldPtr); 285 OS.GlobalFree(oldPtr); 286 COM.VariantClear(newPtr); OS.GlobalFree(newPtr); 291 if (autoVar != null) 293 autoVar.dispose(); 294 } 295 } 296 311 public IDispatch getDispatch() { 312 if (type == COM.VT_EMPTY) { 313 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 314 } 315 if (type == COM.VT_DISPATCH) { 316 return dispatchData; 317 } 318 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 320 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 321 Variant autoVar = null; try { 323 getData(oldPtr); 324 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_DISPATCH); 325 if (result != COM.S_OK) 326 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 327 autoVar = new Variant(); 328 autoVar.setData(newPtr); 329 return autoVar.getDispatch(); 330 } finally { 331 COM.VariantClear(oldPtr); 332 OS.GlobalFree(oldPtr); 333 COM.VariantClear(newPtr); OS.GlobalFree(newPtr); 338 if (autoVar != null) 340 autoVar.dispose(); 341 } 342 } 343 356 public boolean getBoolean() { 357 if (type == COM.VT_EMPTY) { 358 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 359 } 360 if (type == COM.VT_BOOL) { 361 return booleanData; 362 } 363 364 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 366 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 367 try { 368 getData(oldPtr); 369 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_BOOL); 370 if (result != COM.S_OK) 371 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 372 Variant boolVar = new Variant(); 373 boolVar.setData(newPtr); 374 return boolVar.getBoolean(); 375 } finally { 376 COM.VariantClear(oldPtr); 377 OS.GlobalFree(oldPtr); 378 COM.VariantClear(newPtr); 379 OS.GlobalFree(newPtr); 380 } 381 } 382 390 public int getByRef() { 391 if (type == COM.VT_EMPTY) { 392 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 393 } 394 if ((type & COM.VT_BYREF)== COM.VT_BYREF) { 395 return byRefPtr; 396 } 397 398 return 0; 399 } 400 414 public byte getByte() { 415 if (type == COM.VT_EMPTY) { 416 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 417 } 418 if (type == COM.VT_I1) { 419 return byteData; 420 } 421 422 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 424 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 425 try { 426 getData(oldPtr); 427 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_I1); 428 if (result != COM.S_OK) 429 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 430 Variant byteVar = new Variant(); 431 byteVar.setData(newPtr); 432 return byteVar.getByte(); 433 } finally { 434 COM.VariantClear(oldPtr); 435 OS.GlobalFree(oldPtr); 436 COM.VariantClear(newPtr); 437 OS.GlobalFree(newPtr); 438 } 439 } 440 454 public char getChar() { 455 if (type == COM.VT_EMPTY) { 456 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 457 } 458 if (type == COM.VT_UI2) { 459 return charData; 460 } 461 462 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 464 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 465 try { 466 getData(oldPtr); 467 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_UI2); 468 if (result != COM.S_OK) 469 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 470 Variant charVar = new Variant(); 471 charVar.setData(newPtr); 472 return charVar.getChar(); 473 } finally { 474 COM.VariantClear(oldPtr); 475 OS.GlobalFree(oldPtr); 476 COM.VariantClear(newPtr); 477 OS.GlobalFree(newPtr); 478 } 479 } 480 void getData(int pData){ 481 if (pData == 0) OLE.error(OLE.ERROR_OUT_OF_MEMORY); 482 483 COM.VariantInit(pData); 484 485 if ((type & COM.VT_BYREF) == COM.VT_BYREF) { 486 COM.MoveMemory(pData, new short[] {type}, 2); 487 COM.MoveMemory(pData + 8, new int[]{byRefPtr}, 4); 488 return; 489 } 490 491 switch (type) { 492 case COM.VT_EMPTY : 493 case COM.VT_NULL : 494 COM.MoveMemory(pData, new short[] {type}, 2); 495 break; 496 case COM.VT_BOOL : 497 COM.MoveMemory(pData, new short[] {type}, 2); 498 COM.MoveMemory(pData + 8, new int[]{(booleanData) ? COM.VARIANT_TRUE : COM.VARIANT_FALSE}, 2); 499 break; 500 case COM.VT_I1 : 501 COM.MoveMemory(pData, new short[] {type}, 2); 502 COM.MoveMemory(pData + 8, new byte[]{byteData}, 1); 503 break; 504 case COM.VT_I2 : 505 COM.MoveMemory(pData, new short[] {type}, 2); 506 COM.MoveMemory(pData + 8, new short[]{shortData}, 2); 507 break; 508 case COM.VT_I4 : 509 COM.MoveMemory(pData, new short[] {type}, 2); 510 COM.MoveMemory(pData + 8, new int[]{intData}, 4); 511 break; 512 case COM.VT_I8 : 513 COM.MoveMemory(pData, new short[] {type}, 2); 514 COM.MoveMemory(pData + 8, new long[]{longData}, 8); 515 case COM.VT_UI2 : 516 COM.MoveMemory(pData, new short[] {type}, 2); 517 COM.MoveMemory(pData + 8, new char[]{charData}, 2); 518 break; 519 case COM.VT_R4 : 520 COM.MoveMemory(pData, new short[] {type}, 2); 521 COM.MoveMemory(pData + 8, new float[]{floatData}, 4); 522 break; 523 case COM.VT_R8 : 524 COM.MoveMemory(pData, new short[] {type}, 2); 525 COM.MoveMemory(pData + 8, new double[]{doubleData}, 8); 526 break; 527 case COM.VT_DISPATCH : 528 dispatchData.AddRef(); 529 COM.MoveMemory(pData, new short[] {type}, 2); 530 COM.MoveMemory(pData + 8, new int[]{dispatchData.getAddress()}, 4); 531 break; 532 case COM.VT_UNKNOWN : 533 unknownData.AddRef(); 534 COM.MoveMemory(pData, new short[] {type}, 2); 535 COM.MoveMemory(pData + 8, new int[]{unknownData.getAddress()}, 4); 536 break; 537 case COM.VT_BSTR : 538 COM.MoveMemory(pData, new short[] {type}, 2); 539 char[] data = (stringData+"\0").toCharArray(); 540 int ptr = COM.SysAllocString(data); 541 COM.MoveMemory(pData + 8, new int[] {ptr}, 4); 542 break; 543 544 default : 545 OLE.error(SWT.ERROR_NOT_IMPLEMENTED); 546 } 547 } 548 562 public double getDouble() { 563 if (type == COM.VT_EMPTY) { 564 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 565 } 566 if (type == COM.VT_R8) { 567 return doubleData; 568 } 569 570 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 572 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 573 try { 574 getData(oldPtr); 575 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_R8); 576 if (result != COM.S_OK) 577 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 578 Variant doubleVar = new Variant(); 579 doubleVar.setData(newPtr); 580 return doubleVar.getDouble(); 581 } finally { 582 COM.VariantClear(oldPtr); 583 OS.GlobalFree(oldPtr); 584 COM.VariantClear(newPtr); 585 OS.GlobalFree(newPtr); 586 } 587 } 588 589 601 public float getFloat() { 602 if (type == COM.VT_EMPTY) { 603 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 604 } 605 if (type == COM.VT_R4) { 606 return floatData; 607 } 608 609 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 611 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 612 try { 613 getData(oldPtr); 614 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_R4); 615 if (result != COM.S_OK) 616 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 617 Variant floatVar = new Variant(); 618 floatVar.setData(newPtr); 619 return floatVar.getFloat(); 620 } finally { 621 COM.VariantClear(oldPtr); 622 OS.GlobalFree(oldPtr); 623 COM.VariantClear(newPtr); 624 OS.GlobalFree(newPtr); 625 } 626 627 } 628 640 public int getInt() { 641 if (type == COM.VT_EMPTY) { 642 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 643 } 644 if (type == COM.VT_I4) { 645 return intData; 646 } 647 648 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 650 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 651 try { 652 getData(oldPtr); 653 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_I4); 654 if (result != COM.S_OK) 655 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 656 Variant intVar = new Variant(); 657 intVar.setData(newPtr); 658 return intVar.getInt(); 659 } finally { 660 COM.VariantClear(oldPtr); 661 OS.GlobalFree(oldPtr); 662 COM.VariantClear(newPtr); 663 OS.GlobalFree(newPtr); 664 } 665 } 666 680 public long getLong() { 681 if (type == COM.VT_EMPTY) { 682 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 683 } 684 if (type == COM.VT_I8) { 685 return longData; 686 } 687 688 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 690 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 691 try { 692 getData(oldPtr); 693 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_I8); 694 if (result != COM.S_OK) 695 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 696 Variant longVar = new Variant(); 697 longVar.setData(newPtr); 698 return longVar.getLong(); 699 } finally { 700 COM.VariantClear(oldPtr); 701 OS.GlobalFree(oldPtr); 702 COM.VariantClear(newPtr); 703 OS.GlobalFree(newPtr); 704 } 705 } 706 718 public short getShort() { 719 if (type == COM.VT_EMPTY) { 720 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 721 } 722 if (type == COM.VT_I2) { 723 return shortData; 724 } 725 726 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 728 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 729 try { 730 getData(oldPtr); 731 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_I2); 732 if (result != COM.S_OK) 733 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 734 Variant shortVar = new Variant(); 735 shortVar.setData(newPtr); 736 return shortVar.getShort(); 737 } finally { 738 COM.VariantClear(oldPtr); 739 OS.GlobalFree(oldPtr); 740 COM.VariantClear(newPtr); 741 OS.GlobalFree(newPtr); 742 } 743 744 } 745 757 public String getString() { 758 if (type == COM.VT_EMPTY) { 759 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 760 } 761 if (type == COM.VT_BSTR) { 762 return stringData; 763 } 764 765 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 767 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 768 try { 769 getData(oldPtr); 770 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_BSTR); 771 if (result != COM.S_OK) 772 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 773 774 Variant stringVar = new Variant(); 775 stringVar.setData(newPtr); 776 return stringVar.getString(); 777 778 } finally { 779 COM.VariantClear(oldPtr); 780 OS.GlobalFree(oldPtr); 781 COM.VariantClear(newPtr); 782 OS.GlobalFree(newPtr); 783 } 784 } 785 794 public short getType() { 795 return type; 796 } 797 811 public IUnknown getUnknown() { 812 if (type == COM.VT_EMPTY) { 813 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, -1); 814 } 815 if (type == COM.VT_UNKNOWN) { 816 return unknownData; 817 } 818 819 int oldPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 821 int newPtr = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, sizeof); 822 Variant unknownVar = null; try { 824 getData(oldPtr); 825 int result = COM.VariantChangeType(newPtr, oldPtr, (short) 0, COM.VT_UNKNOWN); 826 if (result != COM.S_OK) 827 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE, result); 828 unknownVar = new Variant(); 829 unknownVar.setData(newPtr); 830 return unknownVar.getUnknown(); 831 } finally { 832 COM.VariantClear(oldPtr); 833 OS.GlobalFree(oldPtr); 834 COM.VariantClear(newPtr); OS.GlobalFree(newPtr); 839 if (unknownVar != null) 841 unknownVar.dispose(); 842 } 843 } 844 856 public void setByRef(boolean val) { 857 if ((type & COM.VT_BYREF) == 0 || (type & COM.VT_BOOL) == 0) { 858 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE); 859 } 860 COM.MoveMemory(byRefPtr, new short[]{val ? COM.VARIANT_TRUE : COM.VARIANT_FALSE}, 2); 861 } 862 874 public void setByRef(float val) { 875 if ((type & COM.VT_BYREF) == 0 || (type & COM.VT_R4) == 0) { 876 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE); 877 } 878 COM.MoveMemory(byRefPtr, new float[]{val}, 4); 879 } 880 891 public void setByRef(int val) { 892 if ((type & COM.VT_BYREF) == 0 || (type & COM.VT_I4) == 0) { 893 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE); 894 } 895 COM.MoveMemory(byRefPtr, new int[]{val}, 4); 896 } 897 908 public void setByRef(short val) { 909 if ((type & COM.VT_BYREF) == 0 || (type & COM.VT_I2) == 0) { 910 OLE.error(OLE.ERROR_CANNOT_CHANGE_VARIANT_TYPE); 911 } 912 COM.MoveMemory(byRefPtr, new short[]{val}, 2); 913 } 914 915 void setData(int pData){ 916 if (pData == 0) OLE.error(OLE.ERROR_INVALID_ARGUMENT); 917 918 short[] dataType = new short[1]; 919 COM.MoveMemory(dataType, pData, 2); 920 type = dataType[0]; 921 922 if ((type & COM.VT_BYREF) == COM.VT_BYREF) { 923 int[] newByRefPtr = new int[1]; 924 OS.MoveMemory(newByRefPtr, pData + 8, 4); 925 byRefPtr = newByRefPtr[0]; 926 return; 927 } 928 929 switch (type) { 930 case COM.VT_EMPTY : 931 case COM.VT_NULL : 932 break; 933 case COM.VT_BOOL : 934 short[] newBooleanData = new short[1]; 935 COM.MoveMemory(newBooleanData, pData + 8, 2); 936 booleanData = (newBooleanData[0] != COM.VARIANT_FALSE); 937 break; 938 case COM.VT_I1 : 939 byte[] newByteData = new byte[1]; 940 COM.MoveMemory(newByteData, pData + 8, 1); 941 byteData = newByteData[0]; 942 break; 943 case COM.VT_I2 : 944 short[] newShortData = new short[1]; 945 COM.MoveMemory(newShortData, pData + 8, 2); 946 shortData = newShortData[0]; 947 break; 948 case COM.VT_I4 : 949 int[] newIntData = new int[1]; 950 OS.MoveMemory(newIntData, pData + 8, 4); 951 intData = newIntData[0]; 952 break; 953 case COM.VT_I8 : 954 long[] newLongData = new long[1]; 955 OS.MoveMemory(newLongData, pData + 8, 8); 956 longData = newLongData[0]; 957 break; 958 case COM.VT_UI2 : 959 char[] newCharData = new char[1]; 960 COM.MoveMemory(newCharData, pData + 8, 2); 961 charData = newCharData[0]; 962 break; 963 case COM.VT_R4 : 964 float[] newFloatData = new float[1]; 965 COM.MoveMemory(newFloatData, pData + 8, 4); 966 floatData = newFloatData[0]; 967 break; 968 case COM.VT_R8 : 969 double[] newDoubleData = new double[1]; 970 COM.MoveMemory(newDoubleData, pData + 8, 8); 971 doubleData = newDoubleData[0]; 972 break; 973 case COM.VT_DISPATCH : { 974 int[] ppvObject = new int[1]; 975 OS.MoveMemory(ppvObject, pData + 8, 4); 976 if (ppvObject[0] == 0) { 977 type = COM.VT_EMPTY; 978 break; 979 } 980 dispatchData = new IDispatch(ppvObject[0]); 981 dispatchData.AddRef(); 982 break; 983 } 984 case COM.VT_UNKNOWN : { 985 int[] ppvObject = new int[1]; 986 OS.MoveMemory(ppvObject, pData + 8, 4); 987 if (ppvObject[0] == 0) { 988 type = COM.VT_EMPTY; 989 break; 990 } 991 unknownData = new IUnknown(ppvObject[0]); 992 unknownData.AddRef(); 993 break; 994 } 995 996 case COM.VT_WEIRD_IE7_BSTR : 998 type = COM.VT_BSTR; 999 case COM.VT_BSTR : 1001 int[] hMem = new int[1]; 1003 OS.MoveMemory(hMem, pData + 8, 4); 1004 if (hMem[0] == 0) { 1005 type = COM.VT_EMPTY; 1006 break; 1007 } 1008 int size = COM.SysStringByteLen(hMem[0]); 1011 if (size > 0){ 1012 char[] buffer = new char[(size + 1) /2]; COM.MoveMemory(buffer, hMem[0], size); 1015 stringData = new String (buffer); 1016 } else { 1017 stringData = ""; } 1019 break; 1020 1021 default : 1022 int newPData = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof); 1024 if (COM.VariantChangeType(newPData, pData, (short) 0, COM.VT_R4) == COM.S_OK) { 1025 setData(newPData); 1026 } else if (COM.VariantChangeType(newPData, pData, (short) 0, COM.VT_I4) == COM.S_OK) { 1027 setData(newPData); 1028 } else if (COM.VariantChangeType(newPData, pData, (short) 0, COM.VT_BSTR) == COM.S_OK) { 1029 setData(newPData); 1030 } 1031 COM.VariantClear(newPData); 1032 OS.GlobalFree(newPData); 1033 break; 1034 } 1035} 1036 1037 1043public String toString () { 1044 switch (type) { 1045 case COM.VT_BOOL : 1046 return "VT_BOOL{"+booleanData+"}"; 1047 case COM.VT_I1 : 1048 return "VT_I1{"+byteData+"}"; 1049 case COM.VT_I2 : 1050 return "VT_I2{"+shortData+"}"; 1051 case COM.VT_I4 : 1052 return "VT_I4{"+intData+"}"; 1053 case COM.VT_I8 : 1054 return "VT_I8{"+longData+"}"; 1055 case COM.VT_UI2 : 1056 return "VT_UI2{"+charData+"}"; 1057 case COM.VT_R4 : 1058 return "VT_R4{"+floatData+"}"; 1059 case COM.VT_R8 : 1060 return "VT_R8{"+doubleData+"}"; 1061 case COM.VT_BSTR : 1062 return "VT_BSTR{"+stringData+"}"; 1063 case COM.VT_DISPATCH : 1064 return "VT_DISPATCH{"+(dispatchData == null ? 0 : dispatchData.getAddress())+"}"; 1065 case COM.VT_UNKNOWN : 1066 return "VT_UNKNOWN{"+(unknownData == null ? 0 : unknownData.getAddress())+"}"; 1067 case COM.VT_EMPTY : 1068 return "VT_EMPTY"; 1069 case COM.VT_NULL : 1070 return "VT_NULL"; 1071 } 1072 if ((type & COM.VT_BYREF) != 0) { 1073 return "VT_BYREF|"+(type & ~COM.VT_BYREF)+"{"+byRefPtr+"}"; 1074 } 1075 return "Unsupported Type "+type; 1076} 1077} 1078 | Popular Tags |