SYS-CON Media
 Register Now!
Save $700
Untitled Document
2009 East Gold Sponsors
Untitled Document
2009 East iPhone Gold Sponsors
Untitled Document
2009 East Silver Sponsors
Untitled Document
2009 East Exhibitors
Untitled Document
2009 East Media Sponsors
Untitled Document
2008 West
Platinum Sponsor
Untitled Document
2008 West Gold Sponsors
Untitled Document
2008 West Silver Sponsors
Untitled Document
2008 West Bronze Sponsors
Untitled Document
2008 West Exhibitors
Untitled Document
2008 West Media Sponsors
Untitled Document
2008 East
Platinum Sponsor
Untitled Document
2008 East Gold Sponsors
Untitled Document
2008 East Exhibitors
Untitled Document
2008 East Media Sponsors
Untitled Document
2008 Association Sponsor
Can't Miss RSS Feed
Subscribe to the AJAXWorld.com RSS Feed & Get All The Conference News As It Happens!

2009: Decision Year for RIAs - June 22-23, 2009 New York


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

Latest AJAXWorld RIA Stories
"We did not enter the search business. [Google] entered the phone business. Make no mistake they want to kill the iPhone. We won't let them... I want to go back to that other question first and say one more thing. This don't be evil mantra - It's bullshit." - Steve Jobs at an emp...
Did you know that PHP runs on Windows?? Run Drupal, WordPress, SugarCRM, or other PHP-based apps on Windows today with the free Microsoft Web Platform Installer. Microsoft WebsiteSpark is a specially designed program for PHP Web developers and designers to help you explore runnin...
PivotLink, the leading provider of business intelligence (BI) solutions delivered via Software as a Service (SaaS), announced that Everything Channel's CRN has named its business analytics solution one of the "100 Coolest Cloud Computing Products." The Top 100 Cloud Computing ...
Appcelerator, a platform which is used to develop Apple Tablet applications, on Tuesday, announced the findings of a new poll taken of application developers about their plans to build applications for the Apple Tablet. Taken last week from a pool of 18,000 of Appcelerator's a...
There may be little left for Apple to announce about its purported tablet or iSlate come January 27, a date change since January 26 was noised about. The rumor mill is slowly teasing out all its secrets. The great unveiling, according to the Financial Times, is still supposed...
Untitled Document

Call 201 802-3020 or Click Here to Save $700!

Register Today and
Save $700

Your registrations includes: Golden Pass Delegates will receive full conference access on June 22-23, 2009 including: Lunch and Coffee Breaks, and a Collectible Bag. Includes access to all Conference Sessions including the Technical Sessions, Exhibits, Keynotes, Vendor Technology Presentations, and Power Panels.


Sponsorship Opportunities

AJAXWorld offers the undisputed best platform to position your company as a leading vendor in the fast-emerging marketplace for AJAX and Enterprise Web 2.0.


Please call
(201)802-3020



Who Should Attend?

 CTOs & VPs of Engineering
 Directors of Technology
 Sr. User Interface Architects
 Front-End Engineers
 VCs & Industry Analysts
 Directors of Business Development
 Software Engineers
 Senior Architects
 Application Programmers & Software Developers
 Project Managers
 Web Programmers & Designers
 Companies & Organizations that need to stay in
  front of the latest Web technology

AJAXWorld 2009 East - Tracks

Track 01: Business Value of RIAs | Enterprise RIA
Track 02: User Interface & User Experience
Track 03: RIA Tools
Track 04: iPhone Developer Summit



Brought To You By:

AJAXWorld Magazine is the pre-eminent independent vendor-neutral resource for the fastest growing new segment of the software business: entirely Web-based applications and experiences.

Download the Latest Issue!

AJAXWorld 2009 East Speakers Include...


BERGELT
Open Invention Network

BOEDIGHEIMER
Schwans Shared Services

BOSE
DSine Dynamics

GIROUARD
Magnani Caruso Dutton

HERTZOG
NEXThink

WALKER
DotNetNuke Corporation

WESSENDORF
Oracle

YATIV
Magic Software

CARDEN
OpenSpan

CARRATO
IBM

GURNAMI
JP Morgan Chase

FISHER
SpringSource

WHERRY
Meebo

GRABNER
dynaTrace Software

KRZYSKO
US Department of Defense

LOEWY
WebLayers

AJAXWorld Webcasts



SYS-CON EVENTS


AJAXWorld Keynotes & Power Panels

Get “Rich” Quick: Rapid Prototyping for RIA with ZERO Server Code - by Matt Quinlan
Designing for and Managing Performance in the New Frontier of Rich Internet Applications - by Ben Rushlo
REAs: Rich Enterprise Applications - by Pieter Humphrey
Beyond Widgets: What a RIA Platform Should Offer - by Charles Kendrick
How Can AJAX Improve Homeland Security - by Steve Maryka & Ryan Moquin

AJAXWorld Sessions on SYS-CON.TV

· Bill Scott - Yahoo! UI Library
· David Heinemeier Hansson - AJAX on Rails
· Jesse James Garrett - Elements of User Experience
· Dion Hinchcliffe - Real World AJAX
· Eric Miraglia - Open Source AJAX Development
· Paul Rademacher - Mashing Up Your Web Application
· Adam Sah - Google Gadgets
· Doug Crockford - An Introduction to JavaScript
· David Linthicum - Enterprise Web 2.0
· Patrick Grady - The Imagination & Experience Web

AJAXWorld...All The AJAX Rock Stars in One Spot!


Past Events Archive

Cloud Computing Conference & Expo
2009 East

cloudcomputingexpo
2009east.sys-con.com/
Virtualizatoin Conference & Expo
2009 East

virtualizationconference
2009east.sys-con.com/
Cloud Computing Conference & Expo
2008 West

cloudcomputingexpo
2008west.sys-con.com/
SOAWorld Conference & Expo 2008 West
soaworld2008.com/
Virtualization Conference & Expo 2008 West
virtualizationconference
2008west.sys-con.com
AJAXWorld Conference & Expo 2008 West
ajaxoct08.sys-con.com
SOAWorld Conference & Expo 2008 East
soa2008east.sys-con.com
Virtualization Conference & Expo 2008 East
virt2008east.sys-con.com
AJAXWorld 2008 Conference & Expo East
ajaxmar08.sys-con.com
SOAWorld Conference & Expo 2007 West
www.soaworld2007.com
Virtualization Conference & Expo 2007 West
virt2007west.sys-con.com
AJAXWorld 2007 Conference & Expo West
ajaxoct07.sys-con.com

Join Over 10,000 Early AJAX Adopters
Who Have Attended AJAXWorld
• A&R Edelman
• Academic Enterprise
• Accoona Corp [2 delegates]
• Acxiom
• Adams Capital Management
• Adaptive Edge
• Adaptive Path
• Adobe Systems Incorporated [21 delegates]
• Adobe Systems Romania
• Ajax13
• All Risks, Ltd.
• alliance
• Alliance For Community Care
• AlphaDetail Inc
• Altera Corporation
• Amazon.com [6 delegates]
• Appeon Corporation [2 delegates]
• Apple Computer [5 delegates]
• Apress [3 delegates]
• Arkivio
• ASA
• Astute Solutions
• Avaya Inc [2 delegates]
• Avenda Systems
• Avenue A | Razorfish [3 delegates]
• Axcella, LLC [2 delegates]
• Aximsoft
• Azimyth
• Backbase USA Inc. [4 delegates]
• BAE Systems [2 delegates]
• Bank of America [2 delegates]
• Barkley Evergreen & Partners Interactive
• Bayview Financial [2 delegates]
• BEA Systems [3 delegates]
• Billeo
• BMC Software, Inc. [2 delegates]
• Borland Software Corporation
• Bradford Technologies, Inc [2 delegates]
• Brilliance
• Brocade Communications Systems, Inc. [2 delegates]
• Brookside Capital LLC
• Brulant
• Bungee Labs, Inc [6 delegates]
• Bureau of Labor Statistics
• BUZ Interactive
• Cadena Software
• Calix Networks
• Callidus Software [2 delegates]
• Cambia Security
• Carnegie Mellon West
• Cautella, Inc.
• CBSA
• Celequest [3 delegates]
• Change Vision, Inc.
• Charles E. Kenney, CPA
• Charles Schwab & Co., Inc. [8 delegates]

   read more...