[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problem with olegen.rb

splitDiff

1/16/2006 11:31:00 PM

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

3 Answers

Dave Burt

1/17/2006 1:32:00 PM

0

splitDiff wrote:
> 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


splitDiff

1/17/2006 4:10:00 PM

0

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
using extend(<appropriate early binding method>) but that is not
working either.

> 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

Dave Burt

1/17/2006 10:51:00 PM

0

splitDiff wrote:
> 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_defin...).
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