Can I Develop Enabler Applications Using Visual Studio .NET?

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:

  • Open your solution in Visual Studio .NET
  • Right mouse click on the toolbox (you might have to go to the View menu to show the toolbox)
  • Select "Choose Items" from the pop-up menu
  • Scroll down the listbox in the "COM Components" tab to find the EnbPumpX and EnbSessionX controls, and click on their check boxes (this list includes all COM objects and ActiveX controls registered on your machine)
  • Now click OK

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. (Below is a Visual Studio 2008 example)

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:

  • Open your solution in Visual Studio .NET
  • Go to the Project menu and click on "Add Reference..."
  • Click on the COM tab
  • Scroll down to "psrvr 1.0 Type Library", and click "Select" and "Ok" to complete the process.

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

  VB

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

  C#
  
  using PSRVRLib;
  
  Private Delivery MyDeliveryObject;
  Private Hose MyHoseObject;

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 (Not an issue in VS2008)

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

Session

The code below won't compile in VS 2008 and needs to have the .Getocx() added to the end of it. For the same reason as above. But this is the only place it needs to be used in Visual Studio 2008


  Pump.Session = Session;

Like this


  Pump.Session = Session.Getocx();

GetSummary (Not an issue in VS2008, just decimal not currency return types)

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, C# or another .NET language to develop your Enabler application we suggest you download our VB7 pumpdemo sample or C# 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().

C# Notes

Control Arrays

C# Doesn't support control arrays. To allow there to be a dynamic number of pumps and still have each pump call an event handler (where it's the same event handler for all the pumps) a refrence for each event will need to be given to each instance of the pump. For example see the code below for a DeliveryItemSelected event where the pumps are stored in an array where AxEnbPumpX2 whould be the name of the pump activeX component


  Pump[i].DeliveryItemSelected += AxEnbPumpX2_DeliveryItemSelected;

Casting

As C# is heavily typed a lot of the return types from methods need to be cast to the appropriate type. When The Enabler API specifies an IDispatch* return type you need to add a cast to the appropriate class.

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();


©2005 Integration Technologies Limited
Last revised Wednesday, 04-Nov-2009 18:41:51 EST