Tech Articles


Using Visual .NET Components in PowerBuilder


Microsoft recently released the Interop Forms Toolkit 2.0 in order to allow "developers to incorporate VB.NET Forms and Controls into their VB6 applications" (www.microsoft.com/downloads/details.aspx? FamilyID=934de3c5-dc85-4065-9327-96801e57b81d&DisplayLang=en).

The interesting thing is that it operates by automatically generating a COM Callable Wrapper (CCW) for the VB.NET forms and controls. That means that the .NET visual user controls are not only available to VB6, but to any Win32 application that supports COM, including PowerBuilder.

To test it out, I wrote a simple gradient user object in VB.NET (see Listing 1) and deployed it as an interop user control. I then added it to a PowerBuilder 10.5 window as an ActiveX (see Figure 1).

Everything on the window, with the exception of the gradient control, is standard PowerBuilder stuff. After some simple calculations to determine the combined RGB value the user has selected through the sliders and display it, it is applied to the gradient control through the following (of_calcstart and of_calcend are the routines used to calculate the RGB values):

long ll_start, ll_end
ll_start = of_calcstart()
ll_end = of_calcend()

//This will actually cause two repaints, but I don't care
ole_1.object.StartColor = ll_start
ole_1.object.EndColor = ll_end

The reason there are two repaints is because I force a repaint of the control whenever either the start or end color for the gradient is changed. The repaint happens fast enough so the user doesn't notice there were two.

Note that this technique will work not only for controls that you create in VB.NET, but also for third-party controls that can be used in VB.NET. For example, Figure 2 shows Dundas Charts working within a PowerBuilder window after being exposed as an interop control. Similarily, Figure 3 shows Infragistics' WinChart control operating in a PowerBuilder window.

The Interop Toolkit also allows you to expose VB.NET Forms as ActiveX controls (and has since the original 1.0 version), but I can't see much use for that. The important change with the 2.0 version is support for deploying controls.

Note that if you reference a third-party control in your user control, you will need to provide your own methods that will in turn interact with the third-party control. Just because the third-party control is visually exposed through the control doesn't mean that its properties and methods have been exposed.

In an earlier PBDJ article on CCWs I mentioned how manifests can be used so that such controls can be deployed as side-by-side assemblies and invoked through registry-free COM. That simplifies deployment by not requiring changes to the registry or the GAC. One additional significant feature of the Interop Toolkit is that it automatically generates the manifest information you would need if you opted for that deployment method.

Finally, if you're a bit of a C# snob (as I am), you might be initially put off that Microsoft only released the toolkit with support for VB.NET. Fortunately, a couple of people decided to take matters in their own hands and made additional templates for the toolkit available on the CodeProject Website that make the functionality available in C# as well. In particular, Leon Langleyben made one available just after the release of the 1.0 version of the toolkit that implemented forms (https://www.codeproject.com/kb/vb-interop/vb6interoptoolkit2.aspx), and more recently James Ashley made one available for the 2.0 version of the toolkit and controls (https://www.codeproject.com/Articles/15690/VB-C-Interop-Form-Toolkit).

To be honest, this isn't an ideal solution. What it does allow you to do is take advantage of Visual .NET controls in PowerBuilder now, until such time as PowerBuilder 12 is available and directly supports them.

 

--This article was originally published on PBDJ.

Comments (0)
There are no comments posted here yet

Find Articles by Tag

Graph Window File iOS Encoding Open Source Excel Import Linux OS PowerServer Mobile Automated Testing Debugging ODBC Bug Debugger Validation 32-bit License Outlook Platform Migration GhostScript Source Control OAuth 2.0 Array SnapObjects InfoMaker JSON Database 64-bit Testing SQL .NET Std Framework DevOps PowerBuilder Installation API Event CrypterObject PostgreSQL Database Object Import JSON Debug Authentication Repository Event Handler IDE Script Git Web API SqlModelMapper COM Database Table Data Sort JSONParser PBDOM UI Themes MessageBox Windows 10 Icons Service .NET Assembly Text Jenkins Transaction Database Connection Icon Class OrcaScript Mobile Elevate Conference Database Table Data Configuration C# RichTextEdit Control RibbonBar Design Performance Syntax SVN XML JSONGenerator DataType TLS/SSL UI Menu CoderObject SnapDevelop PDF Deployment SDK PowerBuilder Compiler PowerBuilder (Appeon) SQL Server SqlExecutor Application DataWindow JSON TFS OAuth Database Painter PowerServer Web Messagging DragDrop Variable Azure RESTClient Web Service Proxy Trial Stored Procedure Branch & Merge WinAPI Charts Oracle Database Table Schema Source Code .NET DataStore Android PFC CI/CD External Functions RibbonBar Builder WebBrowser Expression Export JSON PowerScript (PS) Encryption Model Windows OS UI Modernization Error DLL Event Handling TreeView Interface OLE PDFlib Resize PostgreSQL ODBC driver Authorization Export SOAP Filter TortoiseGit ActiveX HTTPClient DataWindow NativePDF Database Profile BLOB REST