Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


PowerBuilder Feature — Calling .NET Assemblies from PowerBuilder Using COM Wrappers
Calling .NET Assemblies from PowerBuilder Using COM Wrappers

I used to implement SMTP for PowerBuilder using a PBNI class that used P.J. Naughter's CPJNSMTPConnection MFC class to do the heavy lifting.

Well, .NET 2.0 changes all that. One of the new features of .NET 2.0 is the introduction of a SMTPClient class. One of the features of .NET since it was introduced is the ability of non-.NET applications to call .NET components through the use of a COM Callable Wrapper (CCW).

I'm going to demonstrate how to use a CCW to use the new SMTPClient class in .NET 2.0. The first thing we'll need to do is create our own .NET component using the new class. We'll start by creating a class library using Visual Studio.NET 2005 (see Figure 1). Note that although I haven't tried it personally, I believe everything that I'm doing is possible with Visual C# Express.

Once we've created the new solution, we should rename the C# file that was automatically created from "Class1" to something a bit more meaningful. We can do that in the Solution Explorer, and we'll be prompted to let Visual Studio apply the change throughout the code (see Figure 2).

We also have to make a couple of adjustments to the project properties. Right-click on the project and select Properties. On the Application tab, we need to select the "Assembly Information..." command button to access the Assembly Information editor.

Once there, we have to check the "Make assembly COM-visible" option. You can also provide values for some of the other assembly properties at this time (see Figure 3).

We're going to be adding our assembly to the Global Assembly Cache (GAC), and we need to have a strong name for it to do that. So we go to the Signing tab of the Project properties and check the "Sign the assembly" option. Then click the dropdown list box under "Choose a strong name key file" and select the "" option. This displays the Create Strong Key Name dialog. I've chosen not to assign a password to it (see Figure 4).

Using this dialog automatically creates the strong name file and adds it as a reference to the project.

At some point after creating our assembly we're going to have to:

  • Add the assembly to the GAC using the GACUTIL utility and
  • Create a REG file with the COM entries for the registry using the REGASM utility
We can have the compiler do that for us automatically by adding calls to those utilities in a post-build build event (See Figure 5).

Here I'm dynamically creating environmental variables to point to the location of the .NET Framework 2.0 directory (where the REGASM utility is found) and the .NET 2.0 SDK bin directory (where the GACUTIL utility is found). It's not necessary, but it's helpful if you're calling more than one utility in those directories. It also helps makes the later command lines more legible. Note that the call to GACUTIL has quotes around the command line and the TargetPath argument. That's because the path to the .NET 2.0 SDK directory and the TargetPath have embedded spaces and the command will fail if the quotes aren't used.

The output of the REGASM utility is a .REG file, which we'll need to run (double-click) to add the entries into the registry.

So far we've set up a class that can be used as a CCW, but it doesn't have any code it in yet. Go back to the class file and add "using System.NET.Mail" to the using section so we can reference the new SMTPClient classes without having to qualify them fully. Then add the code in Listing 3 to implement the class. Compile the new class, and then (assuming there were no errors) run the REG file to add the COM information to the registry.

We probably want to test out the class to make sure it does what we're expecting. We can do that in Visual Studio.NET 2005 (or Visual C# Express) by creating another project to test the assembly. Create another solution, this time a standard Windows Application. We'll need to add a reference to the assembly, so select Project->Add Reference from the menu, choose the Browse tab in the Add Reference dialog, and then navigate to the assembly in the build directory from the previous project (see Figure 6).

Now drop a CommandButton on the default form, and then double-click on it to bring up the editor for its Click event. Add the code from Listing 1, inserting your own name, e-mail address, and e-mail server. Run the project, and when you click on the button in the form, you should send yourself e-mail using the assembly.

Because of the CCW, it's as easy (perhaps even easier) to call the assembly from PowerBuilder. Just add a CommandButton to a window in PowerBuilder, and add the code from Listing 2 to its clicked event. That's it! You're done. You can use the same technique to call other .NET components. And you'll probably want to expand on this example to add support for authentication to the e-mail server, attachments, multiple recipients, etc. However, the supplied sample should get you well started.

About Bruce Armstrong
Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE