02-24-2010 01:31 PM
I'm using CVI_ActiveApp and CVI_AppGetProjectVersionInfo and so on to mess around with versions.
The ppplications I built with CVI automation runs as part of the build process (get/set version in prj and in a header file).
Everything works fine as long as there is only one CVI instance running.
If there is another CVI instance running and the interisting one is the second, the run of my get/set version app fails (luckily it does) if the first instance has loaded another project than the second because CVI_AppGetAbsPathFromProject doesn't find the mentioned header file because CVI_ActiveApp returns a handle to the first app which project doesnt contain this file.
This confuses me, because the name contains "Active" which means to me that the app handle of the CVI instance is returned which is active (has focus, title bar looks like one of an active window).
Is there a possibility to get the app handle of the app which is really active (as described before)?
03-04-2010 03:46 AM
Maybe this link helps:
Preventing Multiple Instances of a LabWindows/CVI Application from Running at the Same Time
Regards,
03-04-2010 09:34 AM
Here Active does not refer to the app that has the focus - it refers to the app that is 'active' in the COM/ActiveX Running Object Table. Unfortunately, this table is like a queue and the first app that get there becomes the active one - when it exits, the next one becomes active, and so on. This is a COM/ActiveX technology and is not controlled by CVI. So, you really cannot do what you want - get a handle to the second app when the first is still running. My suggestions are:
1) Use the NewApp function to launch a new instance of CVI to do what you want - do not use ActiveApp.
2) Use ActiveApp and when you detect that it is not the instance you want, force that instance to quit and then call ActiveApp again, until you get the correct instance.
03-04-2010 09:51 AM
"Active" does not refer to the instance with window focus, but rather to the currently registered ActiveX server. Depending on whether your multiple running CVI instances are different versions, and the order in which they were launched, any one of them could be the "active" CVI instance. Unfortunately, your problem isn't just one of identifying the instance of CVI you're interested in. The real problem is that when multiple instances are running, there is only one particular instance that may be controlled through automation, and that may not be the one you want. This is a limitation of the CVI automation server, and unfortunately, I don't think there is a way around this. You could repeatedly call CVI_ActiveApp and CVI_AppExitCVI until CVI_AppGetAbsPathFromProject succeeds, but that may not be a satisfactory approach for you.
Mert A.
National Instruments
03-04-2010 01:12 PM
Thank you all for your answers. I'm now understanding the results I got.
@ AndreasS: It's the CVI IDE application I want to control. Even if I had the possibility to insert a mutex I want to have more than one instance running (eg. client + server + test app).
I think I will try the approach of "manipulating" the queue by exiting and starting CVI.