The OCX files must be registered in order to use them or to build the .NET samples. The installer does this automatically, but you can reregister or unregister them using Microsoft's regsvr32.exe utility or the ActiveX Test Container that comes with Visual Studio. The test container in Visual Studio under "Tools/ActiveX Test container" is the 32 bit version. 64 bit ocx files require the 64 bit version.
To register the OCX files with regsrv32.exe Utility, on both 32 bit and 64 bit operation systems do the following:
Open a Command Line window. Type in the folowing line to Register or Reregister the OCX:
regsvr32.exe "C:\folder\BiDIB.ocx"
To Un-register the OCX, use the folowing line:
regsvr32.exe /u "C:\folder\BiDIB.ocx"
Visual Studio can create two different kinds of OCX wrappers in the .NET:
- One with Ax prefix (displayable component)
- One without Ax prefix (simple wrapper)
The .NET samples contain both of the wrappers.
Wrapper with Ax prefix
The wrapper with Ax prefix is a displayable component what can be placed on a forms.
The wrapper with Ax prefix generated when the OCX component added to the Toolbox of the Visual Studio and the component placed on a form (or control).
The following describes how to add an OCX component to the Toolbox:
-Right click on Toolbox
-Select “Choose items…”
-Select “COM components” tab
-Select the OCX from the list and click on OK
When the component is placed into a From by the visual designer, Visual Studio generates the code automatically what initialize the displayable component.
Wrapper without Ax prefix
The wrapper without Ax prefix is a simple wrapper (not a displayable component).
The wrapper without Ax prefix created when the reference of the OCX added to the Visual Studio project.
The following describes how to add an OCX reference to the project:
-Select “Project/Add reference”
-Select the COM tab
-Select the OCX from the list and click on OK
The generated wrapper no needs to initialize before use.
Example:
AxBIDIBLib.AxBIDIB oDib = new AxBIDIBLib.AxBIDIB();
oDib.CreateControl();
int wid = oDib.GetDIBWidth(e.hDib);
The displayable component created programmatically (not with the visual designer). Thus the component needs to be initialized manually (by CreateControl).
The preferred way is using the without Ax prefix version of the wrapper when creating the control programmatically and no need to display the component.
Example:
BIDIBLib.BIDIBClass oDib = new BIDIBLib.BIDIBClass();
int wid = oDib.GetDIBWidth(e.hDib);
To use the ActiveX controls from .NET applications in Visual Studio right-click on the References section of the project and select Add Reference from the context menu. Find the control you want to use on the COM page and click ok. By doing this, Visual Studio generates two runtime-callable wrappers, (Interop.*Lib.dll, AxInterop.*Lib.dll) making the COM object appear to .NET clients just as if it were a native .NET object.
When adding reference to the 64 bit controls, only one of the wrappers will be generated (Interop.*Lib.dll). This is enough for most of the controls, but some of them (BiDisp and BiThumbnail) require the more complex wrapper based on System.Windows.Forms.AxHost (AxInterop.*Lib.dll). To use these 64bit controls, use the TlbImp.exe utility shipping with Visual Studio to generate the files. We also provide these wrappers for you, they are located in the bin directory of your installations (Ax*Lib.dll, *Lib.dll). To use the manually generated wrappers, right-click on the References section of your project, select Add Reference from the context menu and find the files on the Browse page.