Changeset 192 for Include/com


Ignore:
Timestamp:
Mar 28, 2007, 10:29:58 AM (18 years ago)
Author:
イグトランス (egtra)
Message:

Currencyを追加、その他修正

Location:
Include/com
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • Include/com/bstring.ab

    r175 r192  
    8080    End Sub
    8181
    82     Sub Attach(bstr As BSTR)
     82    Sub Attach(ByRef bstr As BSTR)
    8383        Clear()
    8484        BString.Move(bs, bstr)
  • Include/com/index.ab

    r142 r192  
    22
    33#require <com/bstring.ab>
     4#require <com/variant.ab>
     5#require <com/vbojbect.ab>
     6#require <com/currency.ab>
  • Include/com/variant.ab

    r175 r192  
    2020    End Sub
    2121
    22     Sub Variant(v As VARIANT)
     22    Sub Variant(ByRef y As VARIANT)
    2323        VariantInit(v)
    2424        VariantCopy(v, y)
     
    132132    End Sub
    133133
    134     Sub Assign(from As VARIANT)
    135         Clear()
     134    Sub Assign(ByRef from As VARIANT)
    136135        Variant.Copy(v, from)
     136    End Sub
     137
     138    Sub AssignInd(ByRef from As VARIANT)
     139        VariantCopyInd(v, from)
    137140    End Sub
    138141
     
    141144    End Sub
    142145
     146    Const Function Copy() As VARIANT
     147        Variant.Copy(Copy, v)
     148    End Function
     149
    143150    Function Detach() As VARIANT
    144151        Variant.Move(Detach, v)
     
    153160    End Function
    154161
    155     Function Operator -() As Variant
     162    Const Function Operator +() As Variant
     163        Return New Variant(This)
     164    End Function
     165
     166    Const Function Operator -() As Variant
    156167        Dim ret As Variant
    157168        VarNeg(This.v, ret.v)
     
    219230    End Function
    220231
    221     Function Operator Not() As Variant
     232    Const Function Operator Not() As Variant
    222233        Dim ret As Variant
    223234        VarNot(This.v, ret.v)
     
    237248    End Function
    238249
    239     Function Abs() As Variant
     250    Const Function Abs() As Variant
    240251        Dim ret As Variant
    241252        VarAbs(This.v, ret.v)
     
    243254    End Function
    244255
    245     Function Fix() As Variant
     256    Const Function Fix() As Variant
    246257        Dim ret As Variant
    247258        VarFix(This.v, ret.v)
     
    249260    End Function
    250261
    251     Function Int() As Variant
     262    Const Function Int() As Variant
    252263        Dim ret As Variant
    253264        VarInt(This.v, ret.v)
     
    255266    End Function
    256267
    257     Function Round(cDecimals As Long) As Variant
     268    Const Function Round(cDecimals As Long) As Variant
    258269        Dim ret As Variant
    259270        VarRound(This.v, cDecimals, ret)
     
    261272    End Function
    262273
    263     Function Round() As Variant
     274    Const Function Round() As Variant
    264275        Return Round(0)
    265276    End Function
     
    274285
    275286    Const Function Operator ==(y As Variant) As Boolean
    276         Return Compare(This, y) = VARCMP_EQ
     287        Dim c = Compare(This, y)
     288        If c = VARCMP_EQ Then
     289            Return True
     290        Else
     291            Return False
     292        End If
    277293    End Function
    278294
    279295    Const Function Operator <>(y As Variant) As Boolean
    280         Return Compare(This, y) <> VARCMP_EQ
     296        Dim c = Compare(This, y)
     297        If c <> VARCMP_EQ Then
     298            Return True
     299        Else
     300            Return False
     301        End If
    281302    End Function
    282303
    283304    Const Function Operator <(y As Variant) As Boolean
    284         Return Compare(This, y) = VARCMP_LT
    285     End Function
    286 
    287 '   Const Function Operator >(y As Variant) As Boolean
    288 '       Return Compare(This, y) = VARCMP_GT
    289 '   End Function
    290 
     305        Dim c = Compare(This, y)
     306        If c = VARCMP_LT Then
     307            Return True
     308        Else
     309            Return False
     310        End If
     311    End Function
     312/*
     313    Const Function Operator >(y As Variant) As Boolean
     314        Dim c = Compare(This, y)
     315        If c = VARCMP_GT Then
     316            Return True
     317        Else
     318            Return False
     319        End If
     320    End Function
     321*/
    291322    Const Function Operator <=(y As Variant) As Boolean
    292         Dim result = Compare(This, y)
    293         Return result = VARCMP_LT Or result = VARCMP_EQ
     323        Dim c = Compare(This, y)
     324        If result = VARCMP_LT Or result = VARCMP_EQ Then
     325            Return True
     326        Else
     327            Return False
     328        End If
    294329    End Function
    295330
    296331    Const Function Operator >=(y As Variant) As Boolean
    297         Dim result = Compare(This, y)
    298         Return result = VARCMP_GT Or result = VARCMP_EQ
     332        Dim c = Compare(This, y)
     333        If result = VARCMP_GT Or result = VARCMP_EQ Then
     334            Return True
     335        Else
     336            Return False
     337        End If
    299338    End Function
    300339
     
    469508    'ValDate
    470509
    471     Const Function ValBStr() As BString
     510    Const Function ValStr() As BString
    472511        Dim r As VARIANT
    473512        ChangeType(r, 0, VT_BSTR)
     
    477516    End Function
    478517
    479     Sub ValBStr(x As BString)
     518    Sub ValStr(x As BString)
    480519        Clear()
    481520        v.vt = VT_BSTR
     
    497536    Const Function ValObject() As VBObject
    498537        Dim r As VARIANT
    499         ChangeType(r, 0, VT_DISPATH)
    500         Dim o As VBOBject
     538        ChangeType(r, 0, VT_DISPATCH)
     539        Dim o As VBObject
    501540        o.Attach(GetPointer(VarPtr(r.val)) As *IDispatch)
    502541        Return o
     
    517556        Return VarPtr(v)
    518557    End Function
     558
    519559Private
    520560    v As VARIANT
     
    523563        VariantCopy(dst, src)
    524564    End Sub
    525        
     565
    526566
    527567    Static Sub Move(ByRef dst As VARIANT, ByRef src As VARIANT)
  • Include/com/vbobject.ab

    r186 r192  
    1212    End Sub
    1313
    14     Sub VBObject(className As String)
    15         VBObject(ToWCStr(className))
    16     End Sub
    17 
    18     Sub VBObject(className As PCWSTR)
     14    Sub VBObject(className As String, pOuter As *IUnknown, clsContext As DWord)
     15        VBObject(ToWCStr(className), pOuter, clsContext)
     16    End Sub
     17
     18    Sub VBObject(className As PCSTR, pOuter As *IUnknown, clsContext As DWord)
     19        VBObject(ToWCStr(className), pOuter, clsContext)
     20    End Sub
     21
     22    Sub VBObject(className As PCWSTR, pOuter As *IUnknown, clsContext As DWord)
    1923        pdisp = 0
    2024        Dim clsid As CLSID
    2125        Dim hr = _System_CLSIDFromString(className, clsid)
    22         Dim hr2 = CoCreateInstance(clsid, 0, CLSCTX_ALL, IID_IDispatch, pdisp)
     26        VBObject(clsid, pOuter, clsContext)
     27    End Sub
     28
     29    Sub VBObject(ByRef clsid As CLSID, pOuter As *IUnknown, clsContext As DWord)
     30        Dim hr = CoCreateInstance(clsid, pOuter, clsContext, IID_IDispatch, pdisp)
    2331    End Sub
    2432
     
    5361
    5462    Function Equals(y As VBObject) As Boolean
    55         Dim punkX = GetUnknown()
    56         Dim punkY = y.GetUnknown()
    57         Equals = (punkX == punkY)
    58         punkX->Release()
    59         punkY->Release()
     63        Return _System_COMReferenceEquals(pdisp, y.pdisp)
    6064    End Function
    6165/*
    6266    Override Function GetHashCode() As Long
    63         Dim punk = GetUnknown()
     67        Dim punk = _System_GetUnknown(pdisp)
    6468        GetHashCode = _System_HashFromPtr(punk)
    6569        punk->Release()
     
    7983    End Sub
    8084
    81     Function GetDispatch() As *IDispatch
     85    Function Copy() As *IDispatch
    8286        VBObject.Copy(GetDispatch, pdisp)
    8387    End Function
     
    8892    End Sub
    8993
    90     Sub Detach()
     94    Function Detach() As *IDispatch
    9195        VBObject.Move(Detach, pdisp)
    92     End Sub
     96    End Function
     97
     98    Function Dispatch() As *IDispatch
     99        Dispatch = pdisp
     100    End Function
    93101Private
    94102    Function GetCaller(name As PCWSTR) As DispatchCaller
     
    96104        Dim hr = pdisp->GetIDsOfNames(GUID_NULL, VarPtr(name), 1, LOCALE_USER_DEFAULT, VarPtr(dispid))
    97105        Return New DispatchCaller(pdisp, dispid)
    98     End Function
    99 
    100     Function GetUnknown() As *IUnknown
    101         If FAILDED(pdisp->QueryInterface(IID_Unknown, GetUnknown)) Then
    102             GetUnknown = 0
    103         End If
    104106    End Function
    105107
     
    170172
    171173    Sub Prop(ByRef arg As VARIANT)
    172         Dim dispParams As DISPPARAMS
    173         With dispParams
    174             .rgvarg = VarPtr(arg)
    175             .rgdispidNamedArgs = 0
    176             .cArgs = 1
    177             .cNamedArgs = 1
    178         End With
    179         Dim ret As VARIANT
    180         Dim hr = pdisp->Invoke(dispid, GUID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, dispParams, ret, ByVal 0, 0)
    181         Dispose()
     174        setProp(arg, DISPATCH_PROPERTYPUT)
    182175    End Sub
    183176
     
    187180
    188181    Sub PropRef(ByRef arg As VARIANT)
    189         Dim dispParams As DISPPARAMS
    190         With dispParams
    191             .rgvarg = 1
    192             .rgdispidNamedArgs = 0
    193             .cArgs = VarPtr(arg)
    194             .cNamedArgs = 0
    195         End With
    196         Dim ret As VARIANT
    197         Dim hr = pdisp->Invoke(dispid, GUID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUTREF, dispParams, ret, ByVal 0, 0)
    198         Dispose()
     182        setProp(arg, DISPATCH_PROPERTYPUTREF)
    199183    End Sub
    200184
     
    228212    Function Call(ByRef arg1 As Variant, ByRef arg2 As Variant) As Variant
    229213        Dim arg[1] As VARIANT
    230        
     214
    231215        Return Call(2, VarPtr(arg1) As *VARIANT)
    232216    End Function
    233217
    234218Private
     219    Sub setProp(ByRef arg As VARIANT, callType As Word)
     220        Dim dispidNamed = DISPID_PROPERTYPUT As DISPID
     221        Dim dispParams As DISPPARAMS
     222        With dispParams
     223            .rgvarg = VarPtr(arg)
     224            .rgdispidNamedArgs = VarPtr(dispidNamed)
     225            .cArgs = 1
     226            .cNamedArgs = 1
     227        End With
     228        Dim hr = pdisp->Invoke(dispid, GUID_NULL, LOCALE_USER_DEFAULT, callType, dispParams, ByVal 0, ByVal 0, 0)
     229        Dispose()
     230    End Sub
     231
     232
    235233    pdisp As *IDispatch
    236234    dispid As DISPID
    237235End Class
    238 /*
     236
     237Function CallByName(obj As VBObject, procName As String, callType As Word, cArgs As Long, args As *VARIANT) As Variant
     238    Return CallByName(obj.Dispatch, ToWCStr(procName), callType, cArgs, args)
     239End Function
     240
     241Function CallByName(obj As VBObject, procName As PCWSTR, callType As Word, cArgs As Long, args As *VARIANT) As Variant
     242    Return CallByName(obj.Dispatch, procName, callType, cArgs, args)
     243End Function
     244
     245Function CallByName(obj As *IDispatch, name As PCWSTR, callType As Word, cArgs As Long, args As *VARIANT) As Variant
     246    Dim dispid As DISPID
     247    Dim hr = obj->GetIDsOfNames(GUID_NULL, VarPtr(name), 1, LOCALE_USER_DEFAULT, VarPtr(dispid))
     248    Dim dispParams As DISPPARAMS
     249    With dispParams
     250        .rgvarg = args
     251        .rgdispidNamedArgs = 0
     252        .cArgs = cArgs
     253        .cNamedArgs = 0
     254    End With
     255    Dim ret As VARIANT
     256    hr = obj->Invoke(dispid, GUID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, dispParams, ret, ByVal 0, 0)
     257    CallByName.Attach(ret)
     258    Return CallByName
     259End Function
     260
    239261Function CreateObject(className As PCWSTR) As VBObject
    240262    Return New VBObject(className)
     
    244266    Return New VBObject(ToWCStr(className))
    245267End Function
    246 
     268/*
    247269#ifdef _WIN32_DCOM
    248270Function CreateObject(className As PCWSTR, serverName As PCWSTR) As VBObject
     
    250272    Dim si As COSERVERINFO
    251273    Dim context As DWord
    252     If /*Server = 0 OrElse* / Server[0] = 0 Then
    253         context = CLSCTX_SERVER
    254     Else
    255         context = CLSCTX_REMOTE_SERVER
    256         si.pwszName = serverName
    257     End If
     274    If /*Server = 0 OrElse* / Server[0] = 0 Then
     275        context = CLSCTX_SERVER
     276    Else
     277        context = CLSCTX_REMOTE_SERVER
     278        si.pwszName = serverName
     279    End If
    258280
    259281    Dim hr = _System_CLSIDFromString(className, clsid)
     
    270292        Return Nothing
    271293    End If
    272 End Function   
     294End Function
    273295
    274296Function CreateObject(className As String, serverName As String) As VBObject
     
    279301Function _System_CLSIDFromString(pwString As PCWSTR, ByRef guid As GUID) As HRESULT
    280302    If pwString[0] = &h007b As WCHAR Then
    281         ' 1文字目が { ならクラスIDの文字列表現と見なしCLSIDFromStringで変換。
    282         _System_CLSIDFromString = CLSIDFromString(pwString, guid)
    283     Else
    284         _System_CLSIDFromString = CLSIDFromProgID(pwString, guid)
    285     End If
     303        ' 1文字目が { ならクラスIDの文字列表現と見なしCLSIDFromStringで変換。
     304        _System_CLSIDFromString = CLSIDFromString(pwString, guid)
     305    Else
     306        _System_CLSIDFromString = CLSIDFromProgID(pwString, guid)
     307    End If
     308End Function
     309
     310Function _System_COMReferenceEquals(p As *IUnknown, q As *IUnknown) As Boolean
     311    If p = q Then
     312        Return True
     313    Else If p = 0 Or q = 0 Then
     314        Return False
     315    End If
     316
     317    Dim punkX = _System_GetUnknown(p)
     318    Dim punkY = _System_GetUnknown(q)
     319    If punkX = punkY Then
     320        _System_COMReferenceEquals = True
     321    Else
     322        _System_COMReferenceEquals = False
     323    End If
     324    punkX->Release()
     325    punkY->Release()
     326End Function
     327
     328Function _System_GetUnknown(p As *IUnknown) As *IUnknown 'pは任意のCOMインタフェース
     329    If FAILDED(pdisp->QueryInterface(IID_Unknown, _System_GetUnknown)) Then
     330        GetUnknown = 0
     331    End If
    286332End Function
    287333
Note: See TracChangeset for help on using the changeset viewer.