LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Register Event Callback - the callback VI is not executing

Hi,

I am having trouble getting my callback VI to work.  The ActiveX component I am accessing is a component that has been developed in house using Visual C++.  We have no problem accessing the callback events when we use this component for our Visual Basic examples.

I am properly registering the callback event.  I know that LabView has successfully registered the event. Here is how I know.  I am running the C++ code with LabView as my .exe.  This way I can set breakpoints in both my C++ code and LabView and step back and forth.  The callback event I need the VI for is called Update.  In my component there is an OnUdate event that gets called which in turn calls the Fire_Update event that is part of the ActiveX control.  The Fire_Update method goes through the list of "clients" or connection points before calling the Invoke method that is part of ActiveX automation.  When I register the event callback in LabView the client or connection count is 1.  If I take the register callback event node out of my LabView code, then the client or connection point count is zero.  I am interpreting this to mean that LabView has successfully registered the event with my ActiveX component.

But the Callback VI doesn't seem to get executed.  I have put a message box in the callback VI and I never see it appear.  This is why I don't think the callback VI is getting called.

Does anyone have any experience with this sort of thing?  Is there any way to set breakpoints and step in the callback VI.

When I register the  callback event in LabView, LabView sees all the methods and properties of the activeX control  When I code the callback VI, one of the pieces of data being passed in to the callback VI is an EventInfo structure that is part of my activeX control.  I can wire the event structure in to an automation invoke node and I can see the resulting methods and properties.  I picke the GetResult method and then when I wire this to the next invoke node I can get all my data functions.

So I'm confused.  Everything seems to be in place but I can't figure out why the callback is not executing.

Sorry this is so long but I'm trying to give as much info as possible so that someone may be able to help.

Best regards,
Ira Idelson
0 Kudos
Message 1 of 9
(4,594 Views)
Hello,
 
I understand the problem as you described it, but I am not sure why the callback function would not be executing.  Perhaps as a first round of exploration, you can open an example from the example finder which will demonstrate the use of a callback VI when an event occurs for an activeX object.  Try the example called "ActiveX Event Callback for IE.vi" which can be found in the example finder (launch using Help -> Find Examples...) by searching the keyword callback, and double-clicking that keyword when it populates in the "Double-click Keyword(s)" list.  If you click the "Blocked Site" button and then click the "Load" button, you'll see a dialog box pop up with a silly message - that dialog box is in a callback VI.  There is also an example for Excel you can observe.  Verifying this on your machine will at least ensure the event mechanism is not malfunctioning in general.  If those examples work, it may be worth looking at the code you used to define your custom ActiveX control.  While I am not familiar with building ActiveX controls, perhaps you can look at the code specifically designated to handling events... although the event name may be visible in LabVIEW, and you can register it on the block diagram, perhaps the event firing mechanism for your control is not functioning properly.
 
Ok, I hope this helps, and I look forward to your repost!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 2 of 9
(4,566 Views)
*clarification:
 
When I say "that dialog box is in a callback VI" I don't mean it is the callback VI, rather I mean the one button dialog function which is called by the callback VI, which demonstrates that the callback VI is actually executing.  Please see the code for the callback VI for this.
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 3 of 9
(4,563 Views)
Thanks for the suggestions but I have already tried all of that.
I have looked at both the IE and Excel examples provided with LabView.  I modified those to pop up a one button dialog when the callback VI executes and I indeed see the dialog.  I have tried the same with my control and Callback VI and did not see the dialog pop up.

We have used this ActiveX control with the VB examples we provide to our customers and VB recognizes and responds to the events.  I have stepped all the way through the C++  code and everything is executing.  VB responds to the event, the C++ code we wrote recognizes the event, but LabView does not seem to respond to the event.

I will keep trying.  If I find an answer I will post it.


Ira Idelson


0 Kudos
Message 4 of 9
(4,556 Views)
Hello,
 
It is interesting that the examples work but when you essentially substitute your activeX control in, the callback mechanism doesn't work.  Further interesting is that it works in VB.  Can you post a very simple example - ideally just code and instructions for clicking a button on a front panel which will fire an event in your activeX control, for which your code should have registered a callback VI, which should just call a one button dialog indicating that the code executed.  If you can post this and the activeX control, I will try to register the control on my machine, and run the program to see if I have the same problem on my machine.
 
I look forward to your repost, and if you do figure it out thank you for being willing to post the answer as you noted... it is great to have solutions posted so that future similar problems can use them!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 5 of 9
(4,538 Views)
I have found the source of the problem but have not solved it yet. In short, in order to get Visual Basic to receive events from our ActiveX control we had to create an "invisible window" to post messages to and spawn a thread that fires the callback event.

I have created a stripped down sample project recreating the basic architecture of the invisible window and the asynchronous thread.  I am able to receive the call back event in LabView from this stirpped down example.  In my real control if I send a message to fire the event with spawning the thread, LabView cathces the callback.  But each time I spawn the thread and send the message to fire the callback event LabView does not catch it.  All the proper C++ code is executing and the Invoke call in the Fire_xxxxxx method is being called.

At this point I am convinced now that it is not a LabView problem.  I need to take a long hard look under the covers of our ActiveX control, including the .idl fileto see where the disconnect is occurring.

Thanks
0 Kudos
Message 6 of 9
(4,526 Views)
Hello,
 
Thanks again for the update on your exploration!  I suppose on the one hand it's nice that it doesn't look like LabVIEW, but on the other it's still a problem for you!  If you are able to fix it and have time to post, please do so that it can benefit the community when others encounter similar problems!
 
Thank you again, and best of luck!
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 7 of 9
(4,505 Views)
After more than a week of intense testing, creating test objects to duplicate the architecture of my ActiveX object and finally the addition of the interfaces from my "real" object to my test object I have solved the problem.
 
My ActiveX control generates an event. One of the parameters passed in the C++ event firing code is an interface to another one of our activeX objects, IEventInfo.  IEventInfowas described in its .idl file to be a dispatch interface.  In the COM_MAP of the .h file for the IEventInfo,  we failed add an entry to the COM_MAP of the form COM_INTERFACE_ENTRY2(IDispatch, IEventInfo).
 
When trying to register on of the callback events, for example Initialize, that takes a IEventInfoas a parameter, LabView was aware of the IEventInfoparameter and from the EventData node in the Callback VI I could use the unbundle function to get each subsequent interface from
my IEventInfoparameter.
 
I knew that LabView was receiving the callback event, because in my C++ debugger I could see that LabView threw a first chance exception  everytime the event was fired from my C++ code.
 
It turns out that because I hadn't added COM_INTERFACE_ENTRY2(IDispatch, IEventInfo) to my COM MAP for the EventINfo object, LabView was unable to fire the callback.
0 Kudos
Message 8 of 9
(4,499 Views)

Excellent!

Thank you very much for taking the time to post the solution here.  I am sure others have and will have a similar problem, and will benefit from your exploration and the information you've posted here!  It also helps us understand an instance where others may have trouble using LabVIEW when they are programming and communicating with objects built in multiple development environments.

Thank you again,

Best Regards,

JLS

Best,
JLS
Sixclear
0 Kudos
Message 9 of 9
(4,481 Views)