Can I use the Enabler API in my VS .NET App?

Home > FAQ > Can I use the Enabler API in my VS .NET App?

The simple answer is, "Yes you can".  The Visual Studio .NET tools include support for COM and ActiveX using wrapper classes, so the Enabler ActiveX controls included in the development kit can be used with the new Windows Form Classes.

Adding ActiveX Controls to a .NET Solution

The .NET environment does not allow you to use an ActiveX control directly, since they are not compatible with the new "Windows Forms". Before using an ActiveX control in .NET you need to 'import' the ActiveX control (.OCX file). The import process creates a .NET wrapper class (in C#) for the ActiveX control. It is this class that you interact with in your .NET application.

The wrapper class is a type library that looks like and should behave like any other .NET control. It is responsible for marshalling calls between the .NET runtime and the actual COM object (the ActiveX control).

For this to work you need the OCX file installed and registered - so you need to install The Enabler software on your development PC.

The easiest way to import an ActiveX control is from the IDE:

Once you have completed this process you should have EnbPumpX and EnbSessionX controls displayed in your toolbox. You can now add these to a form in your .NET application.

Visual Studio .NET Customise Toolbox dialog

To make use of The Enabler COM objects associated with the ActiveX controls you also need to add a reference to the Enabler Pump Server. This can be done by following these steps:

Now you can construct Delivery, Hose, Grade, Attendant and Tank objects using the following syntax:


  Private MyDeliveryObject as PSRVRLib.Delivery
  Private MyHoseObject     as PSRVRLib.Hose

Other Material

You can also import a control from the command-line using the "ActiveX Control Importer" (AxImp.EXE) which is in installed as part of the .NET SDK.

Please refer to the MSDN reference for more detailed information about importing and using ActiveX controls in .NET.

Notes

The .NET sample code is provided as a guide only.

State - Namespace clash

When using the System.Windows.Forms.AxHost derived wrapper for ActiveX controls, member names are first mapped to the methods and properties of the AxHost base class, and second to the derived class members. For example, the following code will not compile. Although State is a member of the EnbPumpX control, it is also a member of AxHost (ISerializable):


  PumpControl.State

In the code above, VB7 will resolve the member State to the AxHost member, so you have use the following work-around to resolve the EnbPumpX member correctly. The GetOcx method provides a direct reference to the ActiveX control - this provides a way to resolve the namespace clash:


  PumpControl.GetOcx.State

GetSummary

We have found that the GetSummary methods do not work correctly through the wrapper class. However the data returned by these functions is available using the Delivery, Hose and Grade objects.

Sample Code

If you want to use VB7 or another .NET language to develop your Enabler application we suggest you download our VB7 pumpdemo sample. The sample code is provided to how you can dynamically create the Pump controls, get delivery details, call methods, and implement event handlers.

EnbOptX

If you are using Enabler V3.0 or later, the EnbOPTX control is also available. You will need to import this control if you plan to use the OPT interface.

Control Versions

This sample application was created using the Enabler V3.0 ActiveX controls. If you are using an older version of Enabler your ActiveX control may not have some of the methods used in the sample code. For example .QuickAuthorise() and .QuickSaleSelect().

Troubleshooting

Symptom Solution
CoInitalize fails with result code 0x80010106 This can occur when initalizing COM on the main thread in a managed C++ application. Microsoft has documented a fix for this in a KB article found here: http://support.microsoft.com/kb/824480
Exception for first call to ActiveX control This happens if you dynamically instantiate the ActiveX control but do not add it to the Controls collection.

To correctly add the new control to the form your application should do something like this:

 Pump[i] = new AxEnbPumpX2();
 Pump[i].BeginInit();
 Controls.Add(Pump[i]);
 Pump[i].EndInit();