.NET Programming Hints - Importing ActiveX Controls

<< Click to Display Table of Contents >>

Navigation:  Programming with Common Vision Blox > Compiler specific hints > .NET languages and CVB Programming Hints >

.NET Programming Hints - Importing ActiveX Controls

 

The easiest way to use one of the Common Vision Blox ActiveX controls in any of the Visual Studio languages (managed as well as unmanaged) is to import the ActiveX control into the GUI Toolbox of Visual Studio.

This needs to be done only once per environment - the Toolbox items will be stored persistently by Visual Studio.

 

To add an ActiveX control to the Visual Studio Toolbox, go to the Tools menu choose Choose Toolbox Items or right click on the Toolbox and select Choose Toolbox Items from the context menu (in the context menu it is also possible to remove items or create groups for them).

Doing so will open the Customize Toolbox dialog box with a list of all registered ActiveX Components:

 
CustomizeToolbox

 
Check all the components you want to add to the Toolbox (the Common Vision Blox components' naming pattern is Common Vision ... Control) and press OK.

This will add the selected components to the Toolbox - next time you create a new project with Visual Studio the selected Common Vision Blox controls will already be available in Visual Studio's Toolbox.

 

From here on, the imported ActiveX controls may be simply be used by dropping them into the GUI designer.

If the designer is the Windows Forms designer, dropping the ActiveX control onto the form will automatically create and reference appropriate wrapper DLLs for managed languages (in C++/MFC applications an additional step is required to prompt the generation of the wrappers). If you are planning to target the x64 platform as well (either explicitly or implicitly through an AnyCPU build) you might want to have a look at the section about using ActiveX controls in a .Net application for 64 bit.

 

Common Vision Blox Display Control

The Common Vision Blox Display Control does have two methods that are inherently incompatible with .Net languages: AddOverlayObject and AddUserObject.

Both expect the caller to pass the address of the first element of an array as an integer variable, but the Common Language Runtime has no means of determining the actual length of the array for the purpose of marshaling and will only pass one integer value across the managed/unmanaged boundary.

To work around this issue, the methods AddOverlayObjectNet and AddUserObjectNet have been added to the Common Vision Blox Display Control.

Those methods should be used whenever trying to add a user or overlay object to the display control.

 

Please also note that using user objects in managed code has limitations.

When user objects are being used, the Display control will raise the UserPaint event in which the (unmanaged) handle to the display's Device Context is being passed. To use the drawing functions in System.Drawing this handle can (and needs to) be wrapped in a System.Drawing.Graphics object, but doing so will slightly change the settings of the device context and make e.g. XOR painting (which is potentially used by the Common Vision Blox display) impossible. Therefore user object painting cannot be expected to behave the same way in managed code as it does in unmanaged applications.