LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing IDispatch from VBScript to VI Server

This is a little complicated, but let me try to explain ...

I wish to create an instance of an automation object in VBScript,
and call a VI passing the created object to the VI, then invoke
methods of the object from within the VI.

The automation object is implemented in ATL and is fully functional
and tested. It has one method - testMethod with no parameters.

This is what my VBScript is similar to:

Option Explicit

Dim labView
Set labView = WScript.CreateObject( "LabView.Application.6" )

Dim viRef
Set viRef = labView.GetVIReference( "C:\LVActiveX\LVActiveX.vi" )
viRef.FPWinOpen True

WScript.Echo viRef.Name

' create the test object and call it's one and only method just to make sure
it works
Dim testObject
Set testObject = WScript.CreateObject( "Test.testObject" )
testObject.testMethod

Dim inNames(3)
inNames(0) = "Input1"
inNames(1) = "Input2"
inNames(2) = "InputRef"
inNames(3) = "MyOutput"

Dim params(3)
params(0) = 5
params(1) = 7
' pass the test objects IDispatch in one of the params
Set params(2) = testObject

viRef.Call inNames, params

WScript.Echo params(3)

WScript.StdIn.ReadLine

labView.Quit

Set testObject = Nothing
Set labView = Nothing



The VI simply takes the 2 numeric inputs, adds together and writes the
output to MyOutput, but also invokes the testMethod on the input
IDispatch reference.

It all works fine except the testMethod is never called from the VI.
Using some debugging I have determined that the input automation reference
in the VI is receiving a NULL.

Any ideas on this would be greatly appreciated .

cheers
0 Kudos
Message 1 of 4
(3,083 Views)
Bumer,

I have tried something similar (using SetControlValue to set the refnum) and all it did was to crash LabVIEW.
This is not a definite answer but first I doubt that a COM object refnum is a valid datatype that can be passed in a call. Second, I also doubt that an object refnum created in one process (wscript.exe) can be used in another (labview.exe). I think that you have to create, manipulate, release an object in the process that created it.


LabVIEW, C'est LabVIEW

0 Kudos
Message 2 of 4
(3,083 Views)
That's what I was thinking also, I was hoping that
somehow the interface marshalling would have created
a proxy to the object before it sent it to the
VI. Thanks for the response

cheers
0 Kudos
Message 3 of 4
(3,083 Views)
Did you ever get a definitive answer to all of this ?
The reason I ask is that I am attempting to do something similar except that I want to start a server running by making a call in labview and once the server has started I need to return a ref back to labview so that I can then make use of the server from within LabView. The server is written in C++ and works very nicely in C++, VB and scripting applications. I have recently posted much more information on this problem and would like to hear your thoughts.
0 Kudos
Message 4 of 4
(3,083 Views)