Changeset 192 for Include/com/vbobject.ab
- Timestamp:
- Mar 28, 2007, 10:29:58 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/com/vbobject.ab
r186 r192 12 12 End Sub 13 13 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) 19 23 pdisp = 0 20 24 Dim clsid As CLSID 21 25 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) 23 31 End Sub 24 32 … … 53 61 54 62 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) 60 64 End Function 61 65 /* 62 66 Override Function GetHashCode() As Long 63 Dim punk = GetUnknown()67 Dim punk = _System_GetUnknown(pdisp) 64 68 GetHashCode = _System_HashFromPtr(punk) 65 69 punk->Release() … … 79 83 End Sub 80 84 81 Function GetDispatch() As *IDispatch85 Function Copy() As *IDispatch 82 86 VBObject.Copy(GetDispatch, pdisp) 83 87 End Function … … 88 92 End Sub 89 93 90 Sub Detach()94 Function Detach() As *IDispatch 91 95 VBObject.Move(Detach, pdisp) 92 End Sub 96 End Function 97 98 Function Dispatch() As *IDispatch 99 Dispatch = pdisp 100 End Function 93 101 Private 94 102 Function GetCaller(name As PCWSTR) As DispatchCaller … … 96 104 Dim hr = pdisp->GetIDsOfNames(GUID_NULL, VarPtr(name), 1, LOCALE_USER_DEFAULT, VarPtr(dispid)) 97 105 Return New DispatchCaller(pdisp, dispid) 98 End Function99 100 Function GetUnknown() As *IUnknown101 If FAILDED(pdisp->QueryInterface(IID_Unknown, GetUnknown)) Then102 GetUnknown = 0103 End If104 106 End Function 105 107 … … 170 172 171 173 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) 182 175 End Sub 183 176 … … 187 180 188 181 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) 199 183 End Sub 200 184 … … 228 212 Function Call(ByRef arg1 As Variant, ByRef arg2 As Variant) As Variant 229 213 Dim arg[1] As VARIANT 230 214 231 215 Return Call(2, VarPtr(arg1) As *VARIANT) 232 216 End Function 233 217 234 218 Private 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 235 233 pdisp As *IDispatch 236 234 dispid As DISPID 237 235 End Class 238 /* 236 237 Function 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) 239 End Function 240 241 Function 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) 243 End Function 244 245 Function 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 259 End Function 260 239 261 Function CreateObject(className As PCWSTR) As VBObject 240 262 Return New VBObject(className) … … 244 266 Return New VBObject(ToWCStr(className)) 245 267 End Function 246 268 /* 247 269 #ifdef _WIN32_DCOM 248 270 Function CreateObject(className As PCWSTR, serverName As PCWSTR) As VBObject … … 250 272 Dim si As COSERVERINFO 251 273 Dim context As DWord 252 253 254 255 256 257 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 258 280 259 281 Dim hr = _System_CLSIDFromString(className, clsid) … … 270 292 Return Nothing 271 293 End If 272 End Function 294 End Function 273 295 274 296 Function CreateObject(className As String, serverName As String) As VBObject … … 279 301 Function _System_CLSIDFromString(pwString As PCWSTR, ByRef guid As GUID) As HRESULT 280 302 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 308 End Function 309 310 Function _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() 326 End Function 327 328 Function _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 286 332 End Function 287 333
Note:
See TracChangeset
for help on using the changeset viewer.