Class: WIN32OLE_METHOD

Inherits:
Object
  • Object
show all
Defined in:
lib/win32ole-pr.rb

Constant Summary collapse

IMPLTYPEFLAG_FDEFAULT =
0x1
IMPLTYPEFLAG_FSOURCE =
0x2
IMPLTYPEFLAG_FRESTRICTED =
0x4
IMPLTYPEFLAG_FDEFAULTVTABLE =
0x8

Instance Method Summary collapse

Constructor Details

#initialize(oletype = nil, method = nil) ⇒ WIN32OLE_METHOD

Returns a new instance of WIN32OLE_METHOD.



3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
# File 'lib/win32ole-pr.rb', line 3731

def initialize(oletype=nil, method=nil)
  @pTypeInfo = nil
  @pOwnerTypeInfo = nil
  @index = 0
  return self if oletype.nil?
  if oletype.is_a?(WIN32OLE_TYPE)
    unless method.is_a?(String)
      raise TypeError, "2nd parameter must be String"
    end
    obj = olemethod_from_typeinfo(oletype.pTypeInfo, method)
    if obj.nil?
      raise WIN32OLERuntimeError, "not found #{method}"
    end
  else
    raise TypeError, "1st argument should be WIN32OLE_TYPE object"
  end
end

Instance Method Details

#dispidObject



4077
4078
4079
# File 'lib/win32ole-pr.rb', line 4077

def dispid
  ole_method_dispid(@pTypeInfo, @index)
end

#event?Boolean

Returns:

  • (Boolean)


3976
3977
3978
# File 'lib/win32ole-pr.rb', line 3976

def event?
  ole_method_event(@pOwnerTypeInfo, @index, self.name)
end

#event_interfaceObject



3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
# File 'lib/win32ole-pr.rb', line 3980

def event_interface
  if event?
    name = 0.chr * 4
    hr = WIN32OLE_TYPE.ole_docinfo_from_type(@pTypeInfo, name, nil, nil, nil)
    if hr == S_OK
      str = 0.chr * 256
      wcscpy(str, name.unpack('L').first)
      return wide_to_multi(str)
    end
  end
  nil
end

#helpcontextObject



4052
4053
4054
# File 'lib/win32ole-pr.rb', line 4052

def helpcontext
  ole_method_helpcontext(@pTypeInfo, @index)
end

#helpfileObject



4041
4042
4043
# File 'lib/win32ole-pr.rb', line 4041

def helpfile
  ole_method_helpfile(@pTypeInfo, @index)
end

#helpstringObject



4028
4029
4030
# File 'lib/win32ole-pr.rb', line 4028

def helpstring
  ole_method_helpstring(@pTypeInfo, @index)
end

#inspectObject



4205
4206
4207
# File 'lib/win32ole-pr.rb', line 4205

def inspect
  "#<#{self.class}:#{self.to_s}>"
end

#invkindObject



3872
3873
3874
# File 'lib/win32ole-pr.rb', line 3872

def invkind
  ole_method_invkind(@pTypeInfo, @index)
end

#invoke_kindObject



3868
3869
3870
# File 'lib/win32ole-pr.rb', line 3868

def invoke_kind
  ole_method_invoke_kind(@pTypeInfo, @index)
end

#nameObject Also known as: to_s



3749
3750
3751
# File 'lib/win32ole-pr.rb', line 3749

def name
  @name
end

#offset_vtblObject



4102
4103
4104
# File 'lib/win32ole-pr.rb', line 4102

def offset_vtbl
  ole_method_offset_vtbl(@pTypeInfo, @index)
end

#ole_method_dispid(pTypeInfo, method_index) ⇒ Object



4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
# File 'lib/win32ole-pr.rb', line 4056

def ole_method_dispid(pTypeInfo, method_index)
  dispid = nil
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  return dispid if hr != S_OK
  pFuncDesc = p.unpack('L').first
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  dispid = funcDesc[0, 4].unpack('L').first
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  dispid
end

#ole_method_docinfo_from_type(pTypeInfo, method_index, name, helpstr, helpcontext, helpfile) ⇒ Object



3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
# File 'lib/win32ole-pr.rb', line 3993

def ole_method_docinfo_from_type(pTypeInfo, method_index, name, helpstr, helpcontext, helpfile)
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  getDocumentation = Win32::API::Function.new(table[12], 'PLPPPP', 'L')
  getRefTypeOfImplType = Win32::API::Function.new(table[8], 'PLP', 'L')
  getImplTypeFlags = Win32::API::Function.new(table[9], 'PLP', 'L')
  getRefTypeInfo = Win32::API::Function.new(table[14], 'PLP', 'L')
  releaseTypeAttr = Win32::API::Function.new(table[19], 'PP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  return hr if hr != S_OK
  pFuncDesc = p.unpack('L').first
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  memid = funcDesc[0, 4].unpack('L').first
  hr = getDocumentation.call(pTypeInfo, memid, name, helpstr, helpcontext, helpfile)
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  hr
end

#ole_method_event(pTypeInfo, method_index, method_name) ⇒ Object



3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
# File 'lib/win32ole-pr.rb', line 3906

def ole_method_event(pTypeInfo, method_index, method_name)
  event = false
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getDocumentation = Win32::API::Function.new(table[12], 'PLPPPP', 'L')
  getRefTypeOfImplType = Win32::API::Function.new(table[8], 'PLP', 'L')
  getImplTypeFlags = Win32::API::Function.new(table[9], 'PLP', 'L')
  getRefTypeInfo = Win32::API::Function.new(table[14], 'PLP', 'L')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseTypeAttr = Win32::API::Function.new(table[19], 'PP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getTypeAttr.call(pTypeInfo, p)
  pTypeAttr = p.unpack('L').first
  return event if hr != S_OK
  typeAttr = 0.chr * 76
  memcpy(typeAttr, pTypeAttr, 76)
  if typeAttr[40, 4].unpack('L').first != TKIND_COCLASS
    releaseTypeAttr.call(pTypeInfo, pTypeAttr)
    return event
  end
  for i in 0 ... typeAttr[48, 2].unpack('S').first
    flags = 0.chr * 4
    hr = getImplTypeFlags.call(pTypeInfo, i, flags)
    next if hr != S_OK
    if (flags.unpack('L').first & IMPLTYPEFLAG_FSOURCE) != 0
      href = 0.chr * 4
      hr = getRefTypeOfImplType.call(pTypeInfo, i, href)
      next if hr != S_OK
      href = href.unpack('L').first
      p = 0.chr * 4
      hr = getRefTypeInfo.call(pTypeInfo, href, p)
      next if hr != S_OK
      pRefTypeInfo = p.unpack('L').first
      p = 0.chr * 4
      hr = getFuncDesc.call(pRefTypeInfo, method_index, p)
      if hr != S_OK
        WIN32OLE.ole_release(pRefTypeInfo)
        next
      end
      pFuncDesc = p.unpack('L').first
      funcDesc = 0.chr * 52
      memcpy(funcDesc, pFuncDesc, 52)
      memid = funcDesc[0, 4].unpack('L').first
      bstr = 0.chr * 4
      hr = getDocumentation.call(pRefTypeInfo, memid, bstr, nil, nil, nil)
      if hr != S_OK
        releaseFuncDesc.call(pRefTypeInfo, pFuncDesc)
        WIN32OLE.ole_release(pRefTypeInfo)
        next
      end
      str = 0.chr * 256
      wcscpy(str, bstr.unpack('L').first)
      name = wide_to_multi(str)
      releaseFuncDesc.call(pRefTypeInfo, pFuncDesc)
      WIN32OLE.ole_release(pRefTypeInfo)
      if method_name == name
        event = true
        break
      end
    end
  end
  releaseTypeAttr.call(pTypeInfo, pTypeAttr)
  event
end

#ole_method_helpcontext(pTypeInfo, method_index) ⇒ Object



4045
4046
4047
4048
4049
4050
# File 'lib/win32ole-pr.rb', line 4045

def ole_method_helpcontext(pTypeInfo, method_index)
  helpcontext = 0.chr * 4
  hr = ole_method_docinfo_from_type(pTypeInfo, method_index, nil, nil, helpcontext, nil)
  return nil if hr != S_OK
  helpcontext.unpack('L').first
end

#ole_method_helpfile(pTypeInfo, method_index) ⇒ Object



4032
4033
4034
4035
4036
4037
4038
4039
# File 'lib/win32ole-pr.rb', line 4032

def ole_method_helpfile(pTypeInfo, method_index)
  bhelpfile = 0.chr * 4
  hr = ole_method_docinfo_from_type(pTypeInfo, method_index, nil, nil, nil, bhelpfile)
  return nil if hr != S_OK
  str = 0.chr * 256
  wcscpy(str, bhelpfile.unpack('L').first)
  wide_to_multi(str)
end

#ole_method_helpstring(pTypeInfo, method_index) ⇒ Object



4019
4020
4021
4022
4023
4024
4025
4026
# File 'lib/win32ole-pr.rb', line 4019

def ole_method_helpstring(pTypeInfo, method_index)
  bhelpstring = 0.chr * 4
  hr = ole_method_docinfo_from_type(pTypeInfo, method_index, nil, bhelpstring, nil, nil)
  return nil if hr != S_OK
  str = 0.chr * 256
  wcscpy(str, bhelpstring.unpack('L').first)
  wide_to_multi(str)
end

#ole_method_invkind(pTypeInfo, method_index) ⇒ Object



3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
# File 'lib/win32ole-pr.rb', line 3830

def ole_method_invkind(pTypeInfo, method_index)
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  pFuncDesc = p.unpack('L').first
  if hr != S_OK
    raise WIN32OLERuntimeError, "failed to GetFuncDesc"
  end
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  invkind = funcDesc[16, 4].unpack('L').first
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  invkind
end

#ole_method_invoke_kind(pTypeInfo, method_index) ⇒ Object



3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
# File 'lib/win32ole-pr.rb', line 3851

def ole_method_invoke_kind(pTypeInfo, method_index)
  type = "UNKNOWN"
  invkind = ole_method_invkind(pTypeInfo, method_index)
  if (invkind & INVOKE_PROPERTYGET) != 0 && (invkind & INVOKE_PROPERTYPUT) != 0
    type = "PROPERTY"
  elsif (invkind & INVOKE_PROPERTYGET) != 0
    type = "PROPERTYGET"
  elsif (invkind & INVOKE_PROPERTYPUT) != 0
    type = "PROPERTYPUT"
  elsif (invkind & INVOKE_PROPERTYPUTREF) != 0
    type = "PROPERTYPUTREF"
  elsif (invkind & INVOKE_FUNC) != 0
    type = "FUNC"
  end
  type
end

#ole_method_offset_vtbl(pTypeInfo, method_index) ⇒ Object



4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
# File 'lib/win32ole-pr.rb', line 4081

def ole_method_offset_vtbl(pTypeInfo, method_index)
  offset_vtbl = nil
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  return offset_vtbl if hr != S_OK
  pFuncDesc = p.unpack('L').first
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  offset_vtbl = funcDesc[28, 2].unpack('S').first
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  offset_vtbl
end

#ole_method_params(pTypeInfo, method_index) ⇒ Object



4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
# File 'lib/win32ole-pr.rb', line 4156

def ole_method_params(pTypeInfo, method_index)
  params = []
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  getNames = Win32::API::Function.new(table[7], 'PLPLP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  return params if hr != S_OK
  pFuncDesc = p.unpack('L').first
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  memid = funcDesc[0, 4].unpack('L').first
  cParams = funcDesc[24, 2].unpack('S').first
  bstrs = 0.chr * 4 * (cParams + 1)
  len = 0.chr * 4
  hr = getNames.call(pTypeInfo, memid, bstrs, cParams + 1, len)
  if hr != S_OK
    releaseFuncDesc.call(pTypeInfo, pFuncDesc)
    params
  end
  if cParams > 0
    for i in 1 ... len.unpack('L').first
      param = WIN32OLE_PARAM.new
      param.pTypeInfo = pTypeInfo
      WIN32OLE.ole_addref(pTypeInfo)
      param.method_index = method_index
      param.index = i - 1
      bstr = bstrs[i*4, 4].unpack('L').first
      str = 0.chr * 256
      wcscpy(str, bstr)
      SysFreeString(bstr)
      param.name = wide_to_multi(str)
      params.push(param)
    end
  end
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  params
end

#ole_method_return_type(pTypeInfo, method_index) ⇒ Object



3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
# File 'lib/win32ole-pr.rb', line 3755

def ole_method_return_type(pTypeInfo, method_index)
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  pFuncDesc = p.unpack('L').first
  if hr != S_OK
    raise WIN32OLERuntimeError, "failed to GetFuncDesc"
  end
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  type = WIN32OLE_TYPE.ole_typedesc2val(pTypeInfo, funcDesc[32, 8], nil)
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  type
end

#ole_method_return_type_detail(pTypeInfo, method_index) ⇒ Object



3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
# File 'lib/win32ole-pr.rb', line 3805

def ole_method_return_type_detail(pTypeInfo, method_index)
  type = []
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  pFuncDesc = p.unpack('L').first
  return type if hr != S_OK

  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  WIN32OLE_TYPE.ole_typedesc2val(pTypeInfo, funcDesc[32, 8], type)
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  type
end

#ole_method_return_vtype(pTypeInfo, method_index) ⇒ Object



3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
# File 'lib/win32ole-pr.rb', line 3780

def ole_method_return_vtype(pTypeInfo, method_index)
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  pFuncDesc = p.unpack('L').first
  if hr != S_OK
    raise WIN32OLERuntimeError, "failed to GetFuncDesc"
  end
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  vvt = funcDesc[36, 2].unpack('S').first
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  vvt
end

#ole_method_size_opt_params(pTypeInfo, method_index) ⇒ Object



4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
# File 'lib/win32ole-pr.rb', line 4131

def ole_method_size_opt_params(pTypeInfo, method_index)
  size_opt_params = nil
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  return size_opt_params if hr != S_OK
  pFuncDesc = p.unpack('L').first
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  size_opt_params = funcDesc[26, 2].unpack('S').first
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  size_opt_params
end

#ole_method_size_params(pTypeInfo, method_index) ⇒ Object



4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
# File 'lib/win32ole-pr.rb', line 4106

def ole_method_size_params(pTypeInfo, method_index)
  size_params = nil
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  return size_params if hr != S_OK
  pFuncDesc = p.unpack('L').first
  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  size_params = funcDesc[24, 2].unpack('S').first
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  size_params
end

#ole_method_sub(pOwnerTypeInfo, pTypeInfo, name) ⇒ Object



3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
# File 'lib/win32ole-pr.rb', line 3643

def ole_method_sub(pOwnerTypeInfo, pTypeInfo, name)
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  getNames = Win32::API::Function.new(table[7], 'PLPLP', 'L')
  getDocumentation = Win32::API::Function.new(table[12], 'PLPPPP', 'L')
  releaseTypeAttr = Win32::API::Function.new(table[19], 'PP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getTypeAttr.call(pTypeInfo, p)
  if hr != S_OK
    raise WIN32OLERuntimeError, "failed to GetTypeAttr"
  end
  pTypeAttr = p.unpack('L').first
  typeAttr = 0.chr * 76
  memcpy(typeAttr, pTypeAttr, 76)
  method = nil
  for i in 0 .. typeAttr[44, 2].unpack('S').first
    break if method != nil
    p = 0.chr * 4
    hr = getFuncDesc.call(pTypeInfo, i, p)
    next if hr != S_OK
    pFuncDesc = p.unpack('L').first
    funcDesc = 0.chr * 52
    memcpy(funcDesc, pFuncDesc, 52)
    memid = funcDesc[0, 4].unpack('L').first
    bstr = 0.chr * 4
    hr = getDocumentation.call(pTypeInfo, memid, bstr, nil, nil, nil)
    if hr != S_OK
      releaseFuncDesc.call(pTypeInfo, pFuncDesc)
      next
    end
    str = 0.chr * 256
    wcscpy(str, bstr.unpack('L').first)
    fname = wide_to_multi(str)
    if name.casecmp(fname)==0
      olemethod_set_member(pTypeInfo, pOwnerTypeInfo, i, fname)
      method = self
    end
    releaseFuncDesc.call(pTypeInfo, pFuncDesc)
    pFuncDesc = nil
  end
  releaseTypeAttr.call(pTypeInfo, pTypeAttr)
  method
end

#ole_method_visible(pTypeInfo, method_index) ⇒ Object



3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
# File 'lib/win32ole-pr.rb', line 3876

def ole_method_visible(pTypeInfo, method_index)
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  getFuncDesc = Win32::API::Function.new(table[5], 'PLP', 'L')
  releaseFuncDesc = Win32::API::Function.new(table[20], 'PP', 'L')
  p = 0.chr * 4
  hr = getFuncDesc.call(pTypeInfo, method_index, p)
  pFuncDesc = p.unpack('L').first
  return false if hr != S_OK

  funcDesc = 0.chr * 52
  memcpy(funcDesc, pFuncDesc, 52)
  if (funcDesc[48, 2].unpack('S').first & (FUNCFLAG_FRESTRICTED |
      FUNCFLAG_FHIDDEN |
      FUNCFLAG_FNONBROWSABLE)) != 0
    visible = false
  else
    visible = true
  end
  releaseFuncDesc.call(pTypeInfo, pFuncDesc)
  visible
end

#olemethod_from_typeinfo(pTypeInfo, name) ⇒ Object



3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
# File 'lib/win32ole-pr.rb', line 3693

def olemethod_from_typeinfo(pTypeInfo, name)
  lpVtbl = 0.chr * 4
  table = 0.chr * 88
  memcpy(lpVtbl, pTypeInfo, 4)
  memcpy(table, lpVtbl.unpack('L').first, 88)
  table = table.unpack('L*')
  pTypeAttr = 0.chr * 4
  getRefTypeOfImplType = Win32::API::Function.new(table[8], 'PLP', 'L')
  getTypeAttr = Win32::API::Function.new(table[3], 'PP', 'L')
  getRefTypeInfo = Win32::API::Function.new(table[14], 'PLP', 'L')
  releaseTypeAttr = Win32::API::Function.new(table[19], 'PP', 'L')
  p = 0.chr * 4
  hr = getTypeAttr.call(pTypeInfo, p)
  if hr != S_OK
    raise WIN32OLERuntimeError, "failed to GetTypeAttr"
  end
  method = ole_method_sub(0, pTypeInfo, name)
  return method if method
  pTypeAttr = p.unpack('L').first
  typeAttr = 0.chr * 76
  memcpy(typeAttr, pTypeAttr, 76)
  for i in 0 ... typeAttr[48, 2].unpack('S').first
    break if method
    p = 0.chr * 4
    hr = getRefTypeOfImplType.call(pTypeInfo, i, p)
    next if hr != S_OK
    href = p.unpack('L').first
    p = 0.chr * 4
    hr = getRefTypeInfo.call(pTypeInfo, href, p)
    next if hr != S_OK
    pRefTypeInfo = p.unpack('L').first
    method = ole_method_sub(pTypeInfo, pRefTypeInfo, name)
    WIN32OLE.ole_release(pRefTypeInfo)
  end
  releaseTypeAttr.call(pTypeInfo, pTypeAttr)
  method
end

#olemethod_set_member(pTypeInfo, pOwnerTypeInfo, index, name) ⇒ Object



3633
3634
3635
3636
3637
3638
3639
3640
3641
# File 'lib/win32ole-pr.rb', line 3633

def olemethod_set_member(pTypeInfo, pOwnerTypeInfo, index, name)
  @pTypeInfo = pTypeInfo
  WIN32OLE.ole_addref(pTypeInfo)
  @pOwnerTypeInfo = pOwnerTypeInfo
  WIN32OLE.ole_addref(pOwnerTypeInfo) if pOwnerTypeInfo != 0
  @index = index
  @name = name
  self
end

#paramsObject



4201
4202
4203
# File 'lib/win32ole-pr.rb', line 4201

def params
  ole_method_params(@pTypeInfo, @index)
end

#return_typeObject



3776
3777
3778
# File 'lib/win32ole-pr.rb', line 3776

def return_type
  ole_method_return_type(@pTypeInfo, @index)
end

#return_type_detailObject



3826
3827
3828
# File 'lib/win32ole-pr.rb', line 3826

def return_type_detail
  ole_method_return_type_detail(@pTypeInfo, @index)
end

#return_vtypeObject



3801
3802
3803
# File 'lib/win32ole-pr.rb', line 3801

def return_vtype
  ole_method_return_vtype(@pTypeInfo, @index)
end

#size_opt_paramsObject



4152
4153
4154
# File 'lib/win32ole-pr.rb', line 4152

def size_opt_params
  ole_method_size_opt_params(@pTypeInfo, @index)
end

#size_paramsObject



4127
4128
4129
# File 'lib/win32ole-pr.rb', line 4127

def size_params
  ole_method_size_params(@pTypeInfo, @index)
end

#visible?Boolean

Returns:

  • (Boolean)


3902
3903
3904
# File 'lib/win32ole-pr.rb', line 3902

def visible?
  ole_method_visible(@pTypeInfo, @index)
end