|
Comments
|
Today's Top SOA Links
Tips & Tools Calling .NET Components from PowerBuilder
Via COM Wrappers – revisited
By: Bruce Armstrong
Jan. 11, 2011 06:30 AM
I've written a number of articles in the past on using .NET components, both visual and non-visual, from a PowerBuilder "Classic" (i.e., Win32) application. Until now, all of them involved using a .NET component that was either provided in the .NET Framework or created using Visual Studio. What changes with PowerBuilder 12 is that we can now write a non-visual component using PowerBuilder.NET, so the solution is entirely PowerBuilder based. Technically, this really first became possible with the introduction of the .NET assembly target in PowerBuilder 11. However, there were a couple of issues with using this approach at that time:
With PowerBuilder.NET in PowerBuilder 12, we now have a fully CLR compliant PowerScript with a full autoscripting implementation, script validation and better documented syntax. What's more, the assemblies generated by PowerBuilder.NET are marked as COM visible, so it's much easier to expose them to Win32 applications via CCW. Creating the Assembly
Now that we have a non-visual object that contains these methods, we create a .NET assembly project to tell PowerBuilder to generate that non-visual object as an assembly (see Figures 1 and 2). Deploy the project (creating the assembly) and we're halfway done.
Creating CCW Registry Entries for the Assembly The way you get those registry entries is by running the REGASM utility from the .NET SDK on the assembly. I've named this assembly PBSmtpClient.dll, so I would run REGASM on the assembly at the command line as follows: REGASM PBSmtpClient.dll /regfile:PBSmtpClient.reg If you ran REGASM directly against the assembly with no options, it would automatically add the entries to the registry of the machine you ran it on. For a couple of reasons, you might want to generate the registry entries as a registry file and then incorporate it later. One reason is that you might want to use that registry file (or the information in it) to deploy the assembly on other machines. A second reason is specific to 64-bit operating systems, such as the 64-bit version of Windows 7. When you run REGASM on an assembly on a 64-bit operating system, it only creates the registry entries that are required for 64-bit applications. You'll need to do a bit of copy and pasting to add the information needed for 32-bit applications, such as a PowerBuilder Classic application. What you will do is open the registry file and copy and paste the generated registry entries so that there are two sets in the file. Then for the second set, you will search for HKEY_CLASSES_ROOT and replace it with HKEY_CLASSES_ROOT\Wow6432Node. The Wow6432Node is the subkey of all the main registry keys that contain entries used by 32-bit applications. For example, the first entry in the file would look something like this: [HKEY_CLASSES_ROOT\PBSmtpClient.SmtpClient] And after your copy, paste and replace operation, there would be an additional entry in the file that would look like this: [HKEY_CLASSES_ROOT\Wow6432Node\PBSmtpClient.SmtpClient] Once you've done that (assuming you're on a 64-bit system) double-click the registry file to have Windows add the information to the registry. Of course if you're on a 32-bit system, you could do that directly with what REGASM generated. Calling the Assembly from PowerBuilder Classic integer li_rc smtp = CREATE oleobject smtp.DisconnectObject() A Few Final Thoughts Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||