"Masaki Suketa" <masaki.suketa / nifty.ne.jp> wrote in message
news:200208041151.UAA28336 / smtp2.nifty.ne.jp...

> > However, my long term problem with WIN32OLE remains:
> > components with an optional parameter seems to not be working. I got
this
> > document object with a Save method taking a filename and an optional
second
> > parameter. This won't execute.
>
> Could you show me the script which is not working?

First of all the following Visual Basic script does result in a file:

<snip>
Set mdm = CreateObject( "MDM.Document.2")
mdm.Save ("testfile.mdd")
</snip>

I cannot do the same with Ruby.

The problem is with the Save method of the following interface (only the
essential part shown):

[
  odl,
  uuid(C95896B9-F8E6-4CFE-B960-6A667FFA6658),
  helpstring("IDocument Interface"),
  dual,
  oleautomation
]
interface IDocument : IMDMLabeledObject {
    [id(0x0000000b), propget, helpstring("property CurrentVersion")]

....

    HRESULT Versions([out, retval] IVersions** pVal);
    [id(0x00000022), helpstring("method Save")]
    HRESULT Save([in, optional] VARIANT destination);
....
};

Here is the script and the runtime results. I think this has something to do
with optional parameters. I did the same test about a year ago. I did not
have problems using VB script for example.

<snip>
require 'win32ole'

mralias = WIN32OLE.new('mrAliasMap.Mapper')
puts mralias.CreateAlias("this is a long

name").Name
mdm = WIN32OLE.new('MDM.Document.2')
mdm.Save ('testfile.mdd')
puts 'done'
</snip>

The yields

C:\test\w32\win32ole\sample>ruby test.rb
thialona
test.rb:6:in `method_missing': Save (WIN32OLERuntimeError)
    OLE error code:80070057 in <Unknown>
      <No Description>
    HRESULT error code:0x80020009
      Undtagelse opstod
        from test.rb:6

The first output line indicates that another COM component is working
(truncating a long name).

The Com error is partly in danish: "Undtagelse opstod" which translates to
"an exception occurred". Althoug the error says "method missing" this isn't
true. If I change the Save to use two parameters I get a different error;

<snip>
require 'win32ole'

mralias = WIN32OLE.new('mrAliasMap.Mapper')
puts mralias.CreateAlias("this is a long

name").Name
mdm = WIN32OLE.new('MDM.Document.2')
mdm.Save ('testfile.mdd', 0)
puts 'done'
</snip>


This yields

C:\test\w32\win32ole\sample>ruby test.rb
thialona
test.rb:6:in `method_missing': Save (WIN32OLERuntimeError)
    OLE error code:0 in <Unknown>
      <No Description>
    HRESULT error code:0x8002000e
      Ugyldigt antal parametre
        from test.rb:6

The danish message is know:
"Ugyldigt antal parametre" which translates to "Illegal number of
parameters". So clearly the save method is recognized.

If I change the Save method to a non-existing name "Safe", I get the
following output:

C:\test\w32\win32ole\sample>ruby test.rb
thialona
test.rb:6:in `method_missing': Unknown property or method : `Safe'
(WIN32OLERunt
imeError)
    HRESULT error code:0x80020006
      Ukendt navn
        from test.rb:6

The danish text "Ukendt navn" translates to "Unknown name".


Mikkel