Changeset 478 for trunk/Include/com/variant.ab
- Timestamp:
- Mar 13, 2008, 9:06:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/com/variant.ab
r355 r478 1 1 ' com/variant.ab 2 2 3 #ifndef _COM_VARIANT_AB4 #define _COM_VARIANT_AB5 6 '#require <oaidl.ab>7 '#require <oleauto.ab>8 3 '#require <com/index.ab> 9 4 … … 79 74 Sub Variant(bs As BString) 80 75 v.vt = VT_BSTR 81 SetPointer(VarPtr(v.val), SysAllocStringLen(bs.BStr, bs.Length))82 End Sub 83 84 Sub Variant( p As *IUnknown)85 p->AddRef()76 SetPointer(VarPtr(v.val), bs.Copy)) 77 End Sub 78 79 Sub Variant(unk As IUnknown) 80 If Not IsNothing(unk) Then unk.AddRef() 86 81 v.vt = VT_UNKNOWN 87 SetPointer(VarPtr(v.val), p)88 End Sub 89 90 Sub Variant( p As *IDispatch)91 p->AddRef()82 SetPointer(VarPtr(v.val), ObjPtr(unk)) 83 End Sub 84 85 Sub Variant(disp As IDispatch) 86 If Not IsNothing(disp) Then disp.AddRef() 92 87 v.vt = VT_DISPATCH 93 SetPointer(VarPtr(v.val), p)88 SetPointer(VarPtr(v.val), ObjPtr(disp)) 94 89 End Sub 95 90 /* … … 284 279 285 280 Static Function Compare(x As Variant, y As Variant, lcid As LCID, flags As DWord) As HRESULT 286 Return VarCmp( x.v, y.v, lcid, flags)281 Return VarCmp(removeNull(x).v, removeNull(y).v, lcid, flags) 287 282 End Function 288 283 … … 290 285 Return VarCmp(x.v, y.v, LOCALE_USER_DEFAULT, 0) 'VARCMP_NULL = 3を返す場合があるので注意 291 286 End Function 292 /* 287 293 288 Const Function Operator ==(y As Variant) As Boolean 294 289 Dim c = Compare(This, y) 295 If c = VARCMP_EQ Then 296 Return True 297 Else 298 Return False 299 End If 290 Return c = VARCMP_EQ 300 291 End Function 301 292 302 293 Const Function Operator <>(y As Variant) As Boolean 303 294 Dim c = Compare(This, y) 304 If c <> VARCMP_EQ Then 305 Return True 306 Else 307 Return False 308 End If 295 Return c <> VARCMP_EQ 309 296 End Function 310 297 311 298 Const Function Operator <(y As Variant) As Boolean 312 299 Dim c = Compare(This, y) 313 If c = VARCMP_LT Then 314 Return True 315 Else 316 Return False 317 End If 318 End Function 319 /* 300 Return c = VARCMP_LT 301 End Function 302 320 303 Const Function Operator >(y As Variant) As Boolean 321 304 Dim c = Compare(This, y) 322 If c = VARCMP_GT Then 323 Return True 324 Else 325 Return False 326 End If 327 End Function 328 */ 329 /* 305 Return c = VARCMP_GT 306 End Function 307 330 308 Const Function Operator <=(y As Variant) As Boolean 331 309 Dim c = Compare(This, y) 332 If c = VARCMP_LT Or c = VARCMP_EQ Then 333 Return True 334 Else 335 Return False 336 End If 310 Return c = VARCMP_LT Or c = VARCMP_EQ 337 311 End Function 338 312 339 313 Const Function Operator >=(y As Variant) As Boolean 340 314 Dim c = Compare(This, y) 341 If c = VARCMP_GT Or c = VARCMP_EQ Then 342 Return True 343 Else 344 Return False 345 End If 346 End Function 347 */ 315 Return c = VARCMP_GT Or c = VARCMP_EQ 316 End Function 317 348 318 Const Function ChangeType(vt As VARTYPE, flags As Word) As Variant 349 Dim ret = New Variant 350 ChangeType(ret, flags, vt) 351 Return ret 319 ChangeType = New Variant 320 ChangeType(ChangeType, flags, vt) 352 321 End Function 353 322 … … 369 338 370 339 Override Function ToString() As String 371 Dim tmp = ChangeType(VT_BSTR, VARIANT_ALPHABOOL)372 Dim bs = ((tmp.v.val As ULONG_PTR) As BSTR)373 Return New String(bs As PCWSTR, SysStringLen(bs) As Long)340 /*Using*/ Dim bs = ValStr 341 ToString = bs.ToString 342 bstr.Dispose() 'End Using 374 343 End Function 375 344 … … 526 495 527 496 Const Function ValStr() As BString 497 ValStr = New BString 528 498 Dim r As VARIANT 529 499 ChangeType(r, VARIANT_ALPHABOOL, VT_BSTR) 530 Dim bs = New BString 531 bs.Attach(GetPointer(VarPtr(r.val)) As BSTR) 532 Return bs 500 ValStr.Attach(GetPointer(VarPtr(r.val)) As BSTR) 533 501 End Function 534 502 … … 536 504 Clear() 537 505 v.vt = VT_BSTR 538 SetPointer(VarPtr(v.val), x.Copy()) 539 End Sub 540 541 Const Function ValUnknown() As *IUnknown 506 If IsNothing(x) Then 507 SetPointer(VarPtr(v.val), SysAllocStringLen(0)) 508 Else 509 SetPointer(VarPtr(v.val), x.Copy()) 510 End If 511 End Sub 512 513 Const Function ValUnknown() As IUnknown 542 514 Dim r As VARIANT 543 515 ChangeType(r, 0, VT_UNKNOWN) 544 Return GetPointer(VarPtr(r.val)) As *IUnknown 545 End Function 546 547 Sub ValUnknown(x As *IUnknown) 548 Clear() 549 SetPointer(VarPtr(v.val), x) 550 x->AddRef() 516 Return _System_PtrUnknown(r.val As ULONG_PTR As VoidPtr) 517 End Function 518 519 Sub ValUnknown(x As IUnknown) 520 Clear() 521 SetPointer(VarPtr(v.val), ObjPtr(x)) 522 If Not IsNothing(x) Then 523 x.AddRef() 524 End If 551 525 v.vt = VT_UNKNOWN 552 526 End Sub … … 587 561 588 562 Static Function OptionalParam() As Variant 589 ' If _System_VariantOptionalParam = Nothing Then 590 ' 'ToDo マルチスレッド対応 591 VariantOptionalParam = New Variant 592 VariantOptionalParam.ValError = DISP_E_PARAMNOTFOUND 593 ' End If 594 Return VariantOptionalParam 563 If IsNothing(optionalParam) Then 564 Dim t = New Variant 565 t.ValError = DISP_E_PARAMNOTFOUND 566 InterlockedCompareExchangePointer(ByVal VarPtr(optionalParam), ObjPtr(t), 0) 567 End If 568 Return optionalParam 569 End Function 570 571 Static Function Null() As Variant 572 If IsNothing(optionalParam) Then 573 Dim t = New Variant 574 Dim p = t.PtrToVariant 575 p->vt = VT_NULL 576 InterlockedCompareExchangePointer(ByVal VarPtr(optionalParam), ObjPtr(t), 0) 577 End If 578 Return optionalParam 595 579 End Function 596 580 Private … … 605 589 ' src.vt = VT_EMPTY 606 590 End Sub 591 592 Static Function removeNull(v As Variant) As Varinat 593 If IsNothing(v) Then 594 removeNull = Null 595 Else 596 removeNull = v 597 End If 598 End Function 599 600 Static optionalParam = Nothing As Variant 601 Static null = Nothing As Variant 607 602 End Class 608 609 Dim VariantOptionalParam = Nothing As Variant610 603 611 604 /* … … 629 622 End Namespace 'COM 630 623 End Namespace 'ActiveBasic 631 632 #endif '_COM_VARIANT_AB
Note:
See TracChangeset
for help on using the changeset viewer.