Ruby problems calling VB COM using win32ole

Discussion in 'Ruby' started by Andrew Wroe, Jul 12, 2006.

  1. Andrew Wroe

    Andrew Wroe Guest

    Hi,

    I'm experiencing some unusual behaviour trying to use VB COM through
    win32ole in Ruby, and I'm hoping someone might be able to help. I'm
    using Ruby 1.84-19 (final) here.

    I've included the contents of the files I'm using to reproduce these
    issues below. Note that you need VB6 to build the COM DLL, but hopefully
    you'll be able to see what it's doing without this.

    If you run the script, you'll find that it calls a VB subroutine that
    raises an error, and just before this it displays a dialog window saying
    "About to raise error...". However, despite the script only containing
    one call to this subroutine, when you click OK to dismiss the window it
    appears again. Is this a bug or is there an explanation for it?

    The script then calls a VB function that returns an empty variant and an
    uninitialised array in a variant. However, when Ruby tries to display
    the contents of the return value it gives different results, namely
    'nil' and 'false'. I was expecting it to display 'nil' in both cases
    since there is no data available, but perhaps I've misunderstood
    something. Note that until the most recent version, this final call
    would actually generate a segmentation fault!

    Thanks,

    Andrew.


    Problems.rb
    ___________

    require 'win32ole'

    def problems()
    begin
    test = WIN32OLE.new('Project1.Class1')
    test.raiseerror()
    end
    rescue
    puts test.emptyvariant()
    puts test.emptyarray()
    end

    problems()


    Class1.cls
    __________

    VERSION 1.0 CLASS
    BEGIN
    MultiUse = -1 'True
    Persistable = 0 'NotPersistable
    DataBindingBehavior = 0 'vbNone
    DataSourceBehavior = 0 'vbNone
    MTSTransactionMode = 0 'NotAnMTSObject
    END
    Attribute VB_Name = "Class1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = True
    Attribute VB_PredeclaredId = False
    Attribute VB_Exposed = True
    Option Explicit
    Public Function EmptyVariant() As Variant
    End Function
    Public Function EmptyArray() As Variant
    Dim Test() As Variant
    EmptyArray = Test
    End Function
    Public Sub RaiseError()
    MsgBox "About to raise error..."
    Err.Raise vbObjectError
    End Sub


    Project1.vbp
    ____________

    Type=OleDll
    Class=Class1; Class1.cls
    Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\STDOLE2.TLB#OLE
    Automation
    Startup="(None)"
    ExeName32="Project1.dll"
    Command32=""
    Name="Project1"
    HelpContextID="0"
    CompatibleMode="1"
    CompatibleEXE32="Project1.dll"
    MajorVer=1
    MinorVer=0
    RevisionVer=0
    AutoIncrementVer=0
    ServerSupportFiles=0
    VersionCompanyName="BNP Paribas"
    CompilationType=0
    OptimizationType=0
    FavorPentiumPro(tm)=0
    CodeViewDebugInfo=0
    NoAliasing=0
    BoundsCheck=0
    OverflowCheck=0
    FlPointCheck=0
    FDIVCheck=0
    UnroundedFP=0
    StartMode=1
    Unattended=0
    Retained=0
    ThreadPerObject=0
    MaxNumberOfThreads=1
    ThreadingModel=1
     
    Andrew Wroe, Jul 12, 2006
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.