Dear Rubyists!
I’m trying to automate AutoCad 2002 via Win32OLE - since trying that kind of
stuff with excel seemed to be quite easy I went on to try it with the next
app :o)
Unfortunately I ran into problems after just 2 Minutes…
The following snippet of code works however:
require ‘win32ole’
···
acad = WIN32OLE.new(“autocad.application”)
doc = acad.ActiveDocument
ms = doc.ModelSpace
puts " #{acad.name}, Version #{acad.version} "
When I’m trying to draw a line using:
koor1 = [1,1]
koor2 = [10,10]
ms.AddLine(koor1,koor2)
my program crashes with a segmentation fault.
I guess the problem lies in the arrays being passed to the method. I
searched the web/usenet for any hints on how to pass an array to an ole
object but found absolutely nothing.
Any hints?
Michael
P.S.: I’m quite sure that the Autocad-related stuff is right since i copied
from a book about Autocad-VBA-programing
my program crashes with a segmentation fault.
I guess the problem lies in the arrays being passed to the method. I
searched the web/usenet for any hints on how to pass an array to an ole
object but found absolutely nothing.
I am a clueless newbie in Ruby, knowing nearly less than nothing, but
arrays in COM (ie, OLE, ie, ActiveX, whichever name of the week you
like) are often passed as type SAFEARRAY. This is a structure holding
a dynamically allocated array (a traditional array of consecutive
bytes), but, and this is important, it is allocated using a task
allocator. That is, you cannot make one from your heap manager, unless
your heap manager is cooperating with the task allocator.
There is a caveat: there are rules about memory ownership across COM
calls. If you are the caller, and you pass the ARRAY as a top-level IN
parameter only, then you own the memory, and the callee isn’t allowed
to change it, and in this case, I believe you can get away with it not
being allocated from the task allocator.
“pj” peterjohannsen@hotmail.com wrote in message
news:127ce4a9.0303081536.6dd562eb@posting.google.com…
I am a clueless newbie in Ruby, knowing nearly less than nothing, but
arrays in COM (ie, OLE, ie, ActiveX, whichever name of the week you
like) are often passed as type SAFEARRAY. This is a structure holding
a dynamically allocated array (a traditional array of consecutive
bytes), but, and this is important, it is allocated using a task
allocator. That is, you cannot make one from your heap manager, unless
your heap manager is cooperating with the task allocator.
This is extremely poorly documented - I suspect the task allocator is no
different from ordinary memory - except perhaps applying a standard for
synchronizing allocation and deallocation in multiple threads (i.e. no magic
transfer of memory between processs or something). I did implement my own
safe array allocation in an optimized DB engine and returned the result to
the outside world. It appeared to work fairly well. Also, you can implement
you own allocator interface if you can be bothered, so it is not completely
standardized - this was what made me conclude it would be safe to allocate
my own memory as long is I keep ownership of it.
There is a caveat: there are rules about memory ownership across COM
calls. If you are the caller, and you pass the ARRAY as a top-level IN
parameter only, then you own the memory, and the callee isn’t allowed
to change it, and in this case, I believe you can get away with it not
being allocated from the task allocator.
Yes, you need to obey the tricky who owns what rules - you certainly have to
make sure the original allocator deallocates when using non-standard
allocators.
It is very easy to get this wrong with all sorts of by reference flags and
what not.
Mikkel
Well… at least now I know that it’s not my fault 
Thanks for the hint - but I still have no idea how to bypass that prob. Does
anyone have a suggestion?
Michael
pj wrote:
···
my program crashes with a segmentation fault.
I guess the problem lies in the arrays being passed to the method. I
searched the web/usenet for any hints on how to pass an array to an ole
object but found absolutely nothing.
I am a clueless newbie in Ruby, knowing nearly less than nothing, but
arrays in COM (ie, OLE, ie, ActiveX, whichever name of the week you
like) are often passed as type SAFEARRAY. This is a structure holding
a dynamically allocated array (a traditional array of consecutive
bytes), but, and this is important, it is allocated using a task
allocator. That is, you cannot make one from your heap manager, unless
your heap manager is cooperating with the task allocator.
There is a caveat: there are rules about memory ownership across COM
calls. If you are the caller, and you pass the ARRAY as a top-level IN
parameter only, then you own the memory, and the callee isn’t allowed
to change it, and in this case, I believe you can get away with it not
being allocated from the task allocator.