views:

181

answers:

1

Okay, so I'm doing some good OLE' (sorry) automation with ruby and I ran into a weird problem. I'm trying to extract some data from a Type Library. This works in VB:

Dim c As New TControlsLib.LangCombo
Dim l As TControlsLib.Language
Dim converter As New TControlsLib.LcidConverter
c.AddAllSystemLanguages mtAllKnownLanguages, True
For Each l In c.Languages
  Debug.Print l.DisplayName & ";" & converter.IsoAbbreviationFromLcid(l.Lcid)
Next

TControlsLib is the Type Library (Full name: "TRADOS Controls Type Library"). I also know that mtAllKnownLanguages is a constant that equals 3.

So, I tried to do the same in Ruby. Here's my IRB session:

irb(main):001:0> require 'win32ole'
=> true
irb(main):002:0> t = "TRADOS Controls Type Library"
=> "TRADOS Controls Type Library"
irb(main):003:0> c = WIN32OLE_TYPE.new(t, "LangCombo")
=> LangCombo
irb(main):004:0> converter = WIN32OLE_TYPE.new(t, "LcidConverter")
=> LcidConverter
irb(main):005:0> c.ole_methods
=> [QueryInterface, AddRef, Release, GetTypeInfoCount, GetTypeInfo, 
GetIDsOfNames, Invoke, Enabled, Enabled, Languages, Refresh, AddSystemLanguage, 
SelectedItem, SelectedItem, SelectLanguage, Clear, AddAllSystemLanguages, 
DroppedDownHeight, DroppedDownHeight, AddCustomLanguage, AddLanguage, Type, 
Type, RemoveLanguage, OnSelectionChanged]
irb(main):006:0> c.AddAllSystemLanguages(3, true)
NoMethodError: undefined method `AddAllSystemLanguages' for LangCombo:WIN32OLE_TYPE
from (irb):6

I also cannot call any other methods. In fact, it seems I can't call any Type Library methods.

What am I doing wrong?

+1  A: 

I'm not 100% sure, but WIN32OLE_TYPE may only be for extracting information. Try using just the WIN32OLE object. You need to know the server name though, for instance (I'm guessing the server name):

c = WIN32OLE.new('Trados.LangCombo')

And then you should either be able to invoke directly:

c.AddAllSystemLanguages(3, true)

Or use the invoke method on WIN32OLE:

c.invoke("AddAllSystemLanguages", 3, true)
Bob
Thanks! I found the GUID of the type library, and that works asc = WIN32OLE.new('{LONGGUID}')
KTamas
And with an OLE Browser, I've also found the correct server name, which also works.
KTamas