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

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