LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Web Browser ActiveX control with multiple threads in CVI

Hi All,

I am trying to embed a web browser ActiveX control in my code.
I have created a panel with the ActiveX control "Microsoft Web Browser" on the panel's UIR.
In the panel's init code I get its Handle using the GetObjHandleFromActiveXCtrl and
installs a callback for it using InstallCtrlCallback. In both cases I provide the constant
Control ID name found in the panel.h file, "TESTPANEL_LOGBROWSER".

I encounter the problem when I schedule more then one thread with this panel.
On the screen I can only see the last clicked LOGBROWSER control and the other
LOGBROWSER control (on the 2nd thread) is grayed. Only one control can operate at a time.

I tried to create a different ActiveX control per thread using NewActiveXCtrl
or NewActiveXCtrlFromFile.

Using the NewActiveXCtrl the SW could not find the registered GUID (which I think
is {69550BE2-9A78-11D2-BA91-00600827878D} ) and I got ActiveX error -145.

Using the NewActiveXCtrlFromFile with the "C:\\WINNT\\system32\\shdocvw.dll" file
the SW hanged and did not respond.

What shell I do?

Gil
0 Kudos
Message 1 of 14
(5,491 Views)
I am somewhat unclear on your your application is setup. From what I understand, you have two ActiveX controls on your UIR. However, you are only making one call to GetObjHandleFromActiveXCtrl are using the same Control ID for each control.

Have you tried making a unique Control ID for each control, and making two calls to GetObjHandleFromActiveXCtrl, one for each thread?

Scott Y
NI
0 Kudos
Message 2 of 14
(5,465 Views)
Let me try and clear it. I have a single ActiveX control on my UIR panel and I am launching this panel in different threads
I am making a call to GetObjHandleFromActiveXCtrl per thread, when the thread is created.

Gil
0 Kudos
Message 3 of 14
(5,456 Views)
Gil,

I'm not sure what could be going wrong in your application, but my hunch is that maybe you are mixing up your panel/control handles. In order to successfully accomplish what you are trying to do, each instance of your panel (and its respective controls) will need to have unique handles. I've attached an example project that implements the functionality you are trying to get. It contains a panel with an ActiveX web browser embedded in it and the application opens up that panel in two different threads.

Regards,

E. Sulzer
Applications Engineer
National Instruments
E. Sulzer
Applications Engineer
National Instruments
0 Kudos
Message 4 of 14
(5,428 Views)
Dear AESulzer

I would like to thank you for the example code you provided. After looking at your code I reviewed my process and it seems to be the same (except that my two threads are created from the main thread).
I still did not manage to solve this issue.

Regards,

Gil
0 Kudos
Message 5 of 14
(5,408 Views)
Make sure that the very first function you call in your new thread is CA_InitActiveXThreadStyleForCurrentThread (0, COINIT_APARTMENTTHREADED).

Usually the thread needs to explicitly initialize COM to STA for the ActiveX control to work correctly.

Hope this helps
Bilal Durrani
NI
0 Kudos
Message 6 of 14
(5,400 Views)
Hi Bilal,

I have used your suggestion but still have the same phenomena’s where the ActiveX Web Browser control seems to be ‘shared’ by the two threads/panels.

Gil
0 Kudos
Message 7 of 14
(5,393 Views)
Gil,

I have modified the example posted earlier to spawn two threads from the main() function. The web browsers still appear to function independently. I tried to make some modifications that might cause the two ActiveX controls to lose their independence, but I was not able to reproduce the behavior you are seeing.

Please take a look at the attached example. If it works as expected I would like to ask you to build your code into this example. If it does not work, I would like to know specifically what version of CVI and the CVI runtime engine you have on your computer. This can be checked in Add/Remove programs in the Windows control panel.

Scott Y
NI
Message 8 of 14
(5,371 Views)
Hi Scott,

I have used your example and it works very good. But my software uses different methods of thread creation. I have prepared a demo with the methods I use hoping you could help me figure out the problem.

This demo was created with CVI 7.0 and consists of:
Main panel - on the main thread.
Browser panels – each created in separate scheduled thread.
The panel display, panel discard and all access to the ActiveX object are done using a deferred callback function executed on the main thread.

Regards,

Gil
0 Kudos
Message 9 of 14
(5,318 Views)
Hi Gil,

It turns out we only need to move a single line of code in your application to get it to function as expected.

The LoadPanel calls do need to be in the Main threads so that we can create child panels inside the main panel, which was loaded in the main thread. When we do this, the DisplayPanel() function also needs to be called from main. The attached .zip contains this modification.

Scott Y
NI
Message 10 of 14
(5,285 Views)