LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wrap ActiveX control in an lvclass?

Solved!
Go to solution

I'm trying to wrap an ActiveX control in a class. I'm using an Automation Refnum in the private cluster to hold the reference to the class, create the ActiveX instance with Open Automation, and use the private refnum to access the class. All well and good. But without destructor semantics how do I ensure that the ActiveX object is released properly? Also, the private ActiveX refnum seems to revert to null when I transition from vi to vi. Do I have to do an Open Automation after unbundling the refnum each time?

0 Kudos
Message 1 of 3
(2,632 Views)
Solution
Accepted by topic author erikm

Nobody keeps you from implementing constructor and destructor yourself. Create a static dispatch VI that creates an instance of your ActiveX object and create a dynamic dispatch VI to release it (Thus you can inherit from your class if you have to). The semantics to use your wrapper are the same as working with plain ActiveX refnums: You have to call your destructor VI explicitely as you'd have to do with the "Close Reference" primitive. I wrapped a complete hierarchy of COM objects this way and it works fine. BTW, you can take a look at Endevo GOOP Developer Suite: It simplifies working with classes and provides a class template with constructor and destructor as described above. Unfortunately I have no clue why your automation refnum becomes invalid. Do you use it outside your class and accidently close it somewhere? Maybe OT, but if you need an accessor for the private refnum you can use a trick to protect it from being closed: Wire your original refnum to both inputs of a "Variant To Data" primitive and return the resulting refnum: Thus you increment the reference count of your COM object. You can (and have to) close this refnum safely without affecting your private one.

Message 2 of 3
(2,614 Views)

Thanks very much, that's good advice. This will be used by other programmers, but we'll document "you must call the Delete VI when done with the object".

 

The refnum problem was a wicked newbie error; I didn't bundle the opened refnum back into the private cluster in the VI that did the open. For an old(!) C++ programmer, the strictly By Value nature of LabView data storage is tough to get used to.

0 Kudos
Message 3 of 3
(2,601 Views)