LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ActiveX control returns error "This handle is invalid" or "Class not registered"

Modifying the IDL and recompiling has worked very nicely up until now. I'd like to thank you again for your past help, and now throw another one at you. Using this same app, it seems CVI is not generating the event callback registration functions. There is an _Events class with _EventsEvents marked as the source of a list a events. Here is the relevant segment of the ATS.IDL (attached as well):

[
uuid(C25BA76A-9D56-4C94-923C-975081548C25)
]
dispinterface _EventsEvents {
properties:
methods:
[id(0x00000001), helpcontext(0x000207a0)]
void OnError(long ErrorCode);
....

[
uuid(10856348-0CC7-11D5-9128-00A0C95DE712)
]
coclass Events {
[default] dispinterface _Events;
[default, source] dispinterface _EventsEvents;


I would like to be able to catch OnError events and send them to a callback. For your experimentation, you can cause the ATS.exe software (available for download from link above) to throw an error with something like this:

#include ATS.h
#include ATS2.h
...
CAObjHandle hATS2_IAGen, hATS, hATS2;
ATS_New_RabbitGlobal(NULL,1,LOCALE_NEUTRAL,0,&hATS); //create the software obj handle
ATS2_New_ATS2Global (NULL, 1, LOCALE_NEUTRAL, 0, &hATS2); //create the hardware obj handle
ATS2__ATS2GlobalAGen (hATS2, NULL, &hATS2_IAGen); //create the analog generator obj handle
hATS2_IAGen, NULL, ATS2Const_apbChA, "Vrms", 119.2); //This should throw an exception
...

I've tried going into the generated ATS.h/c and changing the function definitions to be more like callback functions, but I'm really out of my league there. Any suggestions on getting CVI to see the events classes for what they really are?
0 Kudos
Message 11 of 18
(1,828 Views)
Hi jlgregg,
 
Its been awhile since we last chatted. Hope things are going well. I verified your findings that CVI is not generating these event callback registration functions. Its weird that in the Advanced Options of the CVI ActiveX Controller Wizard, even with all the hidden flags deleted, we can't see what top-level or event objects are in that type library. All other type libraries we can see the top-level and event objects.  We are currently looking into seeing what is different between this type library and all other type libraries.  I will keep you posted on the findings.
 
Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 12 of 18
(1,797 Views)
I did find that I can get CVI to generate the event class methods by removing the coclass designation in the IDL. However, it obviously doesn't make the callback registration functions when you do this. I'll keep hacking on it this weekend.
0 Kudos
Message 13 of 18
(1,793 Views)
Since I know basically nothing about IDL and CVI's processing to make the .h/c files, it's kind of hard to move forward intelligently. Can you explain to me how CVI normally recognizes ActiveX/COM events?
0 Kudos
Message 14 of 18
(1,792 Views)
Hi jlgregg,
 
LabWindows/CVI as well as other programming languages, check the applications object library, see what objects are creatable and also what events are supported by those objects.  ActiveX servers specify the events they generate as a collection of methods in an event object.  For each event object you select, the wizard generates a set of functions you can use to register callbacks for each event. LabWindows/CVI calls the callbacks when the server generates the events.  R&D is currently looking into why LabWindows/CVI is not grabbing that information correctly.
We are also running more problems even using LabVIEW register events this Audio Precision object. We can see the events in that language, but cannot register anything that belows to that Events class. 
 
I will let you know more information as we dig around.

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 15 of 18
(1,756 Views)
Is it possible, as a work around, to manually write the event callbacks into the ATS.h/c? I really only need the OnError(...) event right now, and I'd like to use it as a proof of concept. I've kind of hacked on this a bit, but can't seem to get it to work.
0 Kudos
Message 16 of 18
(1,741 Views)
The problem here is that the default interface in the event CoClass did not have any methods and properties, which is not common practice. CVI detects this and does not generate any of the event registration functions of this because it thinks there is no way to instantiate the object. So the workaround for this was to take the idl, and add a DoNothing method in the _Events interface. I am attaching the idl and the tlb file for this so you can regenerate the function panel. You will need to use the tlb file to generate the fp.

I must say this is the first time I have seen a type library like this one. The way it's set up is very unusual, which is why you are seeing all these different issues with it.

I tested it with the following code snippet

static CAObjHandle hATS2Object;
static ATSObj_IApplication appObjHandle;
static CAObjHandle globalObjHandle;


HRESULT CVICALLBACK OnError (CAObjHandle caServerObjHandle,
                              void *caCallbackData,
                              long  errorCode)
{
    return 0;   
}

int main (int argc, char *argv[])
{
    ATSObj__Events hEvents;
    HRESULT status;
    ATS2Obj_IAGen hiagenHandle;
   
    status = ATS_New_RabbitGlobal (NULL, 1, LOCALE_NEUTRAL, 0, &globalObjHandle);
    status = ATS__RabbitGlobalEvents(globalObjHandle,0,&hEvents);
    status = ATS__EventsEventsRegOnOnError(hEvents,OnError,0,1,0);
    status = ATS2_New_ATS2Global (NULL, 1, LOCALE_NEUTRAL, 0, &hATS2Object);
    status = ATS2__ATS2GlobalAGen(hATS2Object,0,&hiagenHandle);
    status = ATS2_IAGenSetAmpl(hiagenHandle,0,ATS2Const_apbChA,"Vrms",111.9);


I hope this helps


Bilal Durrani
NI
0 Kudos
Message 17 of 18
(1,738 Views)
It seems all of Audio Precision's stuff is crafted a bit strangely. I wouldn't expect their type library to be any different. Your fix seems to work great. Thanks a ton.
0 Kudos
Message 18 of 18
(1,717 Views)