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

Currencyを追加、その他修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.