# WIN32OLE extension using in/out SAFEARRAYs (Matlab interface

**URL:** <https://www.ruby-forum.com/t/win32ole-extension-using-in-out-safearrays-matlab-interface/53342>\
**Category:** Ruby\
**Created:** [February 1, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/win32ole-extension-using-in-out-safearrays-matlab-interface/53342 "2006-02-01T23:55:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpheath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rpheath](https://www.ruby-forum.com/u/rpheath)\
**Post date:** [February 1, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/win32ole-extension-using-in-out-safearrays-matlab-interface/53342/1 "2006-02-01T23:55:42Z")

</div>

I am having trouble calling a COM object (Matlab) using the excellent  
WIN32OLE Ruby extension. Several other calls have worked fine, but  
this call involves some in/out SAFEARRAYs. Here is the method  
signature.

GetFullMatrix([in] BSTR varname, [in] BSTR workspace,  
[in, out] SAFEARRAY(double) \*pr,  
[in, out] SAFEARRAY(double) \*pi)

The server uses the sizes of the arrays pr and pi to fill them with the  
requested data–hence their dual in/out nature. Does anyone know how  
to properly make a call like this? Is it possible? My most successful  
attempts have given me the following error.

WIN32OLERuntimeError: GetFullMatrix  
OLE error code:0 in   
  
HRESULT error code:0x80020005  
Type mismatch.  
from (irb):30:in `method\_missing’  
from (irb):30  
from :0

In case you’re running on Windows with Matlab installed, here is the  
code I am using.

require ‘win32ole’  
matlab = WIN32OLE.new(‘Matlab.Application’)  
matlab.Execute(‘bob = 1:5;’)  
t1 = Array.new(5, 0.0)  
t2 = t1.dup  
t3 = matlab.GetFullMatrix(‘bob’, ‘base’, t1, t2)

---

<div class="post-metadata">

**Author:** ![rpheath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rpheath](https://www.ruby-forum.com/u/rpheath)\
**Post date:** [February 3, 2006, 9:07am UTC](https://www.ruby-forum.com/t/win32ole-extension-using-in-out-safearrays-matlab-interface/53342/2 "2006-02-03T09:07:10Z")

</div>

Hello,

In message “WIN32OLE extension using in/out SAFEARRAYs (Matlab  
interface)”  
on 06/02/02, “Ryan H.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> requested data–hence their dual in/out nature. Does anyone know how  
> to properly make a call like this? Is it possible? My most successful  
> attempts have given me the following error.

I do not have MATLAB, But I read the web document about  
MATLAB(Japanese).  
And the article discribes Matlab provides GetWorkspaceData for VBScript.  
Because VBScript does not support SAFEARRAY and you can not use  
GetFullMatrix in VBScript.

Win32OLE may be same as VBScript because Win32OLE  
calls GetFullMatrix with VT\_VARIANT|VT\_BYREF or VT\_ARRAY(SAFEARRAY).  
But MATLAB expect VT\_ARRAY|VT\_BYREF (SAFEARRAY \*).  
So you get Type mysmatch error.

> t3 = matlab.GetFullMatrix(‘bob’, ‘base’, t1, t2)

Could you try GetWorkspaceData instead?  
Sorry, but I do not know how to use GetWorkspaceData exactly.

Regards,  
Masaki S.
