From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing array of ints to ActiveX method

I have an ActiveX server that has a method I'm trying to call from LabView 8.2. One of the function parameters is an array of integers. I've declared the function as follows in my IDL file,

[id(3), helpstring("method NSEnumDevice")] HRESULT NSEnumDevice([in] int devIndex, [in] SAFEARRAY(int) *ports);

In LabView I create an array constant that contains integers (number constants). I then wire it to the method parameter input. When I run the program it fails at the call. The error output is "Incorrect Function. in xyz.vi". If I don't have an error output box, I get a popup error that says "LabVIEW:  An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @". In any case I'm certain the method is not even called. If I remove the SAFEARRAY paramter, the call works fine.

I have tried placing an ActiveX variant conversion between the array and the paramter input, and still receive the same error.

I would really appreciate any ideas and help that would help resolve this issue.
Thanks,
-ddixon

0 Kudos
Message 1 of 5
(3,370 Views)
I should also clarify a few things. The ActiveX server is implemented in Python using the win32com Python package. My ActiveX control works properly with VEEPro and Visual Basic.
-ddixon
0 Kudos
Message 2 of 5
(3,363 Views)
Fortunately I was able to determine what I was doing wrong. LabView and Visual Basic for Applications (VBA) only support the VARIANT data type for arrays. Visual Basic, however, supports more descriptive array parameter specifications in IDL. In other words, there are numerous valid ways to declare array parameters in IDL, however, some tools only support a subset. LV only supports VARIANTs. So in the previous IDL example:

[id(3), helpstring("method NSEnumDevice")] HRESULT NSEnumDevice([in] int devIndex, [in] SAFEARRAY(int) *ports);

becomes -

[id(3), helpstring("method NSEnumDevice")] HRESULT NSEnumDevice([in] int devIndex, [in] VARIANT ports, [out, retval] VARIANT *devObj);

Where devObj is an ActiveX wrapped object. VARIANT "ports" is an array of integer values. To specify returning an array of values, you still just use "
[out, retval] VARIANT *array".
--ddixon
0 Kudos
Message 3 of 5
(3,317 Views)
ddixon:

Thank you very much for posting the solution to your problem.

Reegards,

Rudi N.
0 Kudos
Message 4 of 5
(3,302 Views)

LabVIEW does a better job of typing .NET arrays.  Have you tried creating a .NET .dll from the ActiveX one? There's a free command line tool for this from Microsoft:

http://stackoverflow.com/questions/4284797/how-to-extract-typelib-from-a-com-exe-on-command-line

Be sure to run it as administrator.

 

-D

0 Kudos
Message 5 of 5
(2,640 Views)