Problem with olegen.rb

S

splitDiff

Hi all-

A vendor that I work with provides an OLE inteface for scripting its
client application. I wanted to write some test scripts in Ruby, and I
figured that olegen.rb might get me a jump start.

Unfortunately, I am hitting the following error:

uninitialized constant OLEOperation_1::VT_HRESULT (NameError)

I think that this is the offending line:

ret = _setproperty(-536739838, [arg0], [VT_BSTR, VT_HRESULT])

The VT_HRESULT constant appears several places in the code generated by
olegen, so I can't avoid the call.

I tried a brute force:

VT_HRESULT=25

which got me further along in the code, but led to undefined method
errors coming from OLEProperty the next time I called that object.

Any ideas or assistance would be appreciated. Thanks

-splitDiff
 
D

Dave Burt

splitDiff said:
Hi all-
Hi!

A vendor that I work with provides an OLE inteface for scripting its
client application. I wanted to write some test scripts in Ruby, and I
figured that olegen.rb might get me a jump start.

Have you got a script working with normal dynamic Win32OLE? It's usually
more straightforward; use olegen if you need to speed things up.
Unfortunately, I am hitting the following error:

uninitialized constant OLEOperation_1::VT_HRESULT (NameError)

I think that this is the offending line:

ret = _setproperty(-536739838, [arg0], [VT_BSTR, VT_HRESULT])

The VT_HRESULT constant appears several places in the code generated by
olegen, so I can't avoid the call.

I tried a brute force:

VT_HRESULT=25

which got me further along in the code, but led to undefined method
errors coming from OLEProperty the next time I called that object.

Any ideas or assistance would be appreciated. Thanks

OK, is VT_HRESULT meant to be defined in the vendor library? Try
Constants::VT_HRESULT, see if that works. If that works, but it's too
long-winded for you, you can add "include Constants" in your script. If not,
search the file olegen generated for the constant you want -- is it there,
and if so, what module? Or, if you've dropped back to Win32OLE as I
suggested, you can use WIN32OLE.const_load(ole_server, Kernel) to load the
constants directly into the top-level namespace.

Write back if I'm not making sense; it's late :)

Cheers,
Dave
 
S

splitDiff

Dave-

Thanks for the quick response.
Have you got a script working with normal dynamic Win32OLE? It's usually
more straightforward; use olegen if you need to speed things up.

I'm no COM expert, so please steer me right if I'm misinterpreting
anything.

Many of the methods that I need are not available through iDispatch, so
I can't use late binding. That means that standard Win32OLE doesn't get
me where I need to go.

I used olegen to build the early binding references that I need. Olegen
builds interfaces as modules, and I'm not exactly sure how to use them.
I can use the olegen defined classes to create top level objects that
use early binding. But then later property and method calls to those
objects fall back to the late binding versions, or they end up as
OLEProperty objects which don't have the proper methods. I've tried
OK, is VT_HRESULT meant to be defined in the vendor library?

I think the reference to the VT_HRESULT constant was created by
olegen.rb in the section of the code around line 67:

else
if String === t
ts << 'VT_' + t
end
end

So no, the vendor library has no clue about the VT_HRESULT constant. I
would have expected it to be found in WIN32OLE::VARIANT.constants, but
it's not there.

Any suggestions or additional references on how to use WIN32OLE with
early binding, with or without olegen?

Thanks much

-splitDiff
 
D

Dave Burt

splitDiff said:
I'm no COM expert, so please steer me right if I'm misinterpreting
anything.

Many of the methods that I need are not available through iDispatch, so
I can't use late binding. That means that standard Win32OLE doesn't get
me where I need to go.

I think you're right. I'm just used to dealing with IDispatch interfaces.
I used olegen to build the early binding references that I need. Olegen
builds interfaces as modules, and I'm not exactly sure how to use them.
I can use the olegen defined classes to create top level objects that
use early binding. But then later property and method calls to those
objects fall back to the late binding versions, or they end up as
OLEProperty objects which don't have the proper methods. I've tried
using extend(<appropriate early binding method>) but that is not
working either.

The extend takes a module, not a method. You can attach a method, but only
to an object of the appropriate class.

That's if you're not using evil.rb. You can change the OLEProperty objects'
class to the appropriate class using evil's "become" method.

Of course, these aren't great solutions. The only other I can think of is
using WIN32OLE's early binding call methods _getproperty, _invoke and
_setproperty. But you do need the dispatch ID of the method or property to
use these.
I think the reference to the VT_HRESULT constant was created by
olegen.rb in the section of the code around line 67:

else
if String === t
ts << 'VT_' + t
end
end

So no, the vendor library has no clue about the VT_HRESULT constant. I
would have expected it to be found in WIN32OLE::VARIANT.constants, but
it's not there.

Have you tried tracing that "ts" variable further in the generated code? It
looks like a local variable; isn't it exported in some way? What's t?

WIN32OLE::VARIANT has all the constants that may appear in a VARIANT
(according to http://www.marin.clara.net/COM/variant_type_definitions.htm).
I've massaged the full list of constants and appended it to this message.
Any suggestions or additional references on how to use WIN32OLE with
early binding, with or without olegen?

Sorry, I'm out of ideas, apart from WIN32OLE's underscore-prefixed
early-binding methods.

Masaki Suketa, WIN32OLE's maintainer, may have better ideas.

Cheers,
Dave

# COM Variant Type constants
VT_EMPTY = 0
VT_NULL = 1
VT_I2 = 2
VT_I4 = 3
VT_R4 = 4
VT_R8 = 5
VT_CY = 6
VT_DATE = 7
VT_BSTR = 8
VT_DISPATCH = 9
VT_ERROR = 10
VT_BOOL = 11
VT_VARIANT = 12
VT_UNKNOWN = 13
VT_DECIMAL = 14
VT_I1 = 16
VT_UI1 = 17
VT_UI2 = 18
VT_UI4 = 19
VT_I8 = 20
VT_UI8 = 21
VT_INT = 22
VT_UINT = 23
VT_VOID = 24
VT_HRESULT = 25
VT_PTR = 26
VT_SAFEARRAY = 27
VT_CARRAY = 28
VT_USERDEFINED = 29
VT_LPSTR = 30
VT_LPWSTR = 31
VT_FILETIME = 64
VT_BLOB = 65
VT_STREAM = 66
VT_STORAGE = 67
VT_STREAMED_OBJECT = 68
VT_STORED_OBJECT = 69
VT_BLOB_OBJECT = 70
VT_CF = 71
VT_CLSID = 72
VT_VECTOR = 0x1000
VT_ARRAY = 0x2000
VT_BYREF = 0x4000
VT_RESERVED = 0x8000
VT_ILLEGAL = 0xffff
VT_ILLEGALMASKED = 0xfff
VT_TYPEMASK = 0xfff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top