-----Original Message-----
From: James French [mailto:James.French / naturalmotion.com] 
Sent: 08 November 2010 11:36
To: ruby-talk ML
Subject: win32ole enum

Hi Rubyists,

If someone could help me with this I'd be very grateful...

I'm trying to use WIN32OLE to call a method that takes an enum called EUserDefinedTree. I want to set it to kAbsoluteFilePath. I have a handle to the method and ole_type_detail reports the param as type USERDEFINED.

Trouble is I have no idea how to pass in kAbsoluteFilePath as the value.

Can anyone point me in the right direction? I've already had a good google but nothing turned up.

Cheers,
James



Bit of progress:

module CW_CONST
end

#------------------------------------------------------------------------------------------
def initCodeWarrior
  cwApp = WIN32OLE.new('CodeWarrior.CodeWarriorApp')
  
  WIN32OLE.const_load(cwApp, CW_CONST)
  
  puts CW_CONST::KAbsoluteFilePath   # => 0
  puts CW_CONST::KEnvironment        # => 1
  puts CW_CONST::KRegistry           # => 2

  cwApp.CreateUserTree("displayname", "value", CW_CONST::KAbsoluteFilePath,keyname")
end

I can now *access* the enum values I want, but I can't pass one as the third param to CreateUserTree - the method is failing with an uninformative message at any rate. Do I need to convert it into some kind of object?



Finally answering own question: Upgrade to ruby 1.9.1-p430 or ruby 1.9.2-p0nd then do:

cwApp.CreateUserTree("displayname ", "value", WIN32OLE_VARIANT.new(CW_CONST::KAbsoluteFilePath), "keyname")

Repeat: this does not work with 1.8.7.