win32ole confusion

D

Damphyr

OK, I'm trying to wade my way through Rationals Rose RealTime using
their extensibility interface, just to get some information out of
*various* models.
So I need to load one model, do some work, open another model do some
work etc.

The following code works without a problem:
require 'win32ole'
modelname="some_model"
app=WIN32OLE.new('RoseRT.Application')
model=app.OpenModel(modelname)
app.visible
and at the end of the script the RoseRT.Application process is exited.

If I put the same code in an initialize method for a class

class Finder
def initialize modelname
@app=WIN32OLE.new('RoseRT.Application')
@[email protected](modelname)
@app.visible
end
end

I get the following error

/rt_logical.rb:168:in `method_missing': OpenModel (WIN32OLERuntimeError)
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x80020005
Type mismatch. from ./rt_logical.rb:168:in `initialize'
from structure.rb:69:in `new'

If I take the code and put it in a start method in the class

class Finder2
def initialize modelname
@modelname=modelname
@model=nil
@app=nil
end

def start
@app=WIN32OLE.new('RoseRT.Application')
@[email protected](@modelname)
@app.visible
end

def search objectname
raise RuntimeError,"Finder not started" unless @model
#some search thingy
end
end

and then execute the following:

ff=Finder.new('some_model')
begin
ff.search 'capsule'
rescue
ff.start
retry
end

I got the same error as before (once) and then it worked (although at
the end of the script the RoseRT process is not exited).
Not to forget to mention that the class Finder is in a module.
So what am I missing in the whole create/initialize/destroy cycle that
breaks my script? Do I have some racing condition I need to worry about?
Cheers,
V.-


____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.
 
D

Damphyr

Well, I managed to confuse myself even more. I moved the code outside=20
the application and it works. So I probably screwed up.

module Test

class FinderException<RuntimeError
def initialize modelname
@modelname=3Dmodelname
end
end
class Finder
attr_reader :modelname, :model
#Initialize will throw an exception if the model cannot be opened.
def initialize modelname
@modelname=3Dmodelname
@app=3DWIN32OLE.new('RoseRT.Application')
@[email protected](@modelname)
end
=09
def start
@app=3DWIN32OLE.new('RoseRT.Application')
@[email protected](@modelname)
end
=09
def stop
@app.exit
@model=3Dnil
@app=3Dnil
end
=09
def show
raise FinderException.new(@modelname),"This Finder instance is=20
invalid" unless @model
@app.visible=3Dtrue
end
=09
def hide
raise FinderException.new(@modelname),"This Finder instance is=20
invalid" unless @model
@app.visible=3Dfalse
end
end
end

ff=3DTest::Finder.new('a_model')
ff.show
ff.stop
ff.hide
Damphyr said:
OK, I'm trying to wade my way through Rationals Rose RealTime using
their extensibility interface, just to get some information out of
*various* models.
So I need to load one model, do some work, open another model do some
work etc.
=20
The following code works without a problem:
require 'win32ole'
modelname=3D"some_model"
app=3DWIN32OLE.new('RoseRT.Application')
model=3Dapp.OpenModel(modelname)
app.visible
and at the end of the script the RoseRT.Application process is exited.
=20
If I put the same code in an initialize method for a class
=20
class Finder
def initialize modelname
@app=3DWIN32OLE.new('RoseRT.Application')
@[email protected](modelname)
@app.visible
end
end
=20
I get the following error
=20
./rt_logical.rb:168:in `method_missing': OpenModel (WIN32OLERuntimeErro= r)
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x80020005
Type mismatch. from ./rt_logical.rb:168:in `initialize'
from structure.rb:69:in `new'
=20
If I take the code and put it in a start method in the class
=20
class Finder2
def initialize modelname
@modelname=3Dmodelname
@model=3Dnil
@app=3Dnil
end
=20
def start
@app=3DWIN32OLE.new('RoseRT.Application')
@[email protected](@modelname)
@app.visible
end
=20
def search objectname
raise RuntimeError,"Finder not started" unless @model
#some search thingy
end
end
=20
and then execute the following:
=20
ff=3DFinder.new('some_model')
begin
ff.search 'capsule'
rescue
ff.start
retry
end
=20
I got the same error as before (once) and then it worked (although at
the end of the script the RoseRT process is not exited).
Not to forget to mention that the class Finder is in a module.
So what am I missing in the whole create/initialize/destroy cycle that
breaks my script? Do I have some racing condition I need to worry about= ?
Cheers,
V.-
=20
=20
____________________________________________________________________
http://www.freemail.gr - =E4=F9=F1=E5=DC=ED =F5=F0=E7=F1=E5=F3=DF=E1 =E7=
=EB=E5=EA=F4=F1=EF=ED=E9=EA=EF=FD =F4=E1=F7=F5=E4=F1=EF=EC=E5=DF=EF=F5.
http://www.freemail.gr - free email service for the Greek-speaking.
=20
=20


____________________________________________________________________
http://www.freemail.gr - =E4=F9=F1=E5=DC=ED =F5=F0=E7=F1=E5=F3=DF=E1 =E7=EB=
=E5=EA=F4=F1=EF=ED=E9=EA=EF=FD =F4=E1=F7=F5=E4=F1=EF=EC=E5=DF=EF=F5.
http://www.freemail.gr - free email service for the Greek-speaking.
 
B

Bret Pettichord

So what am I missing in the whole create/initialize/destroy cycle that
breaks my script? Do I have some racing condition I need to worry about?

Probably. OLE is an asynchronous protocol. So WIN32OLE.new() can return an
object before it is actually initialized and ready to use.


_____________________
Bret Pettichord
www.pettichord.com
 

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
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top