Win32ole and releasing COM objects


#1

Hi,

I’m using win32ole to automate use of Microsoft Office Document Imaging
(MODI), on Windows Vista. There seems to be problems with getting MODI
to release files that it works with. I.e., calling Close on the MODI
object doesn’t necessarily release the file to other processes
(attempting to delete it gives me an Errno::EACCESS error). A web search
shows that this is a common issue, and the main suggestion in other
languages is to use

System.InteropServies.Marshal.ReleaseComObject(object)

for each object that needs to be released. Do we have access to this
method in Ruby? Or does anyone know another way to deal with this?

Thanks,
Farmer.


#2

Farmer Schlutzenberg wrote:

for each object that needs to be released. Do we have access to this
method in Ruby? Or does anyone know another way to deal with this?

Try WIN32OLE.ole_free or WIN32OLE#ole_free.

WIN32OLE.ole_free(object)
or
object.ole_free

FYI, Win32OLE automatically releases com object when the object
is GCed. And Win32OLE does not release com object until the object
is GCed (except WIN32OLE.ole_free, WIN32OLE#ole_free).

Regards,
Masaki S.


#3

Thanks! That works great, just the sort of thing I was looking for.