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


Calling .NET Components from PowerBuilder
Via COM Wrappers - Redux

Back in August of 2006, I wrote an article about calling .NET components from PowerBuilder using COM wrappers (i.e., CCW). Since I was basing it on a registry entry approach, the technique demonstrated required the component to be added to the GAC, which in turn required that we create a strong name and sign the assembly (besides having it compiled as a COM-visible assembly).

You don't always have access to the GAC or the registry of the machine that you need to deploy your application to. Well, fortunately we have some options. Beginning with Windows XP and Windows Server 2003, the Microsoft operating systems allowed the use of manifest files rather than registry entries for loading COM components. It not only works for regular COM components, but for .NET components that have been exposed as COM-visible. The only difference is how the manifest file is structured.

If you want further information on the details, I'd recommend the following resources:

We actually need two manifest files. We'll only deploy one because the other one is going to be compiled into our .NET assembly.

Component Manifest
The Component Manifest is the first of the manifest files, and the one that will get compiled into the .NET assembly. Actually Windows Server 2003 lets you deploy it as a separate file alongside the assembly. However, since Windows XP requires it to be part of the assembly, and because it's just a better practice, we'll compile it into the assembly.

You can use the Genman32 utility referenced above to automatically create the file for you, or you can simply create it by hand. I'll assume the later to indicate what the different portions of the file do. A manifest is a text file in XML format, so you start off by creating an empty text file with the same name as the assembly except it ends in .manifest rather than .dll. The first two lines of the file are the standard XML file declaration and the standard declaration for a manifest file. That is followed by the assemblyIdentity that identifies this assembly. It has at least two values, the name of the assembly and its version, as specified in the project settings.

Listing 1 - DotNetSMTP.manifest file

<?xml version="1.0__ encoding="UTF-8__ standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1__ manifestVersion="1.0__>
<assemblyIdentity
name="DotNetSMTP"
version="0.0.0.0__
/>
<clrClass
clsid="{4599956A-2686-3D5F-8F14-9E7F45832B6C}"
name="DotNetSMTP.DotNetSMTP"
progid="DotNetSMTP.DotNetSMTP"
threadingModel="Both"
runtimeVersion="v2.0.50727__>
</clrClass>
<file name="DotNetSMTP.dll">
</file>
</assembly>

The next section of the file is where we associate the CLSID, PROGID, and ThreadingModel information that we would normally provide through registry entries. CLSID must match the GUID value that was used in the assembly. Because we're working in the clrClass tag, we know that this is a managed .NET-based COM component. You can use the Registration Free Activation approach with unmanaged code as well, but there's a different tag that the information for those component is provided in.

Note that as with all XML, the tag names are case-sensitive. One minor mistake in either of the manifest files will result in an error message at runtime, often "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem." Fortunately, more information about the specific problem is recorded in the System event log under a "SideBySide" source. For example, if I entered the assemblyIdentity tag as assemblyidentity (all lower case), the event log would show:

Syntax error in manifest or policy file "dotnetinteropsmtp.exe.Manifest" on line 7. The element assemblyidentity
appears as a child of element urn:schemas-microsoft-com:asm.v1^assembly which is not supported by this version of
Windows.

Now that we have a manifest file for the assembly, we need to compile it into the assembly. To do that, we need to create a resource file that references the manifest file. So create another empty text file, except that this one has a .rc extension. You then add the following three lines of code, one of which includes the reference to the manifest file:

DotNetSMTP.rc file
#include <windows.h>
#define MANIFEST_RESOURCE_ID 1
MANIFEST_RESOURCE_ID RT_MANIFEST DotNetSMTP.manifest

You can add the resource file to your VS project as an existing file, but it isn't necessary.

Now we need to compile the resource file. We do that with the .NET Resource Compiler (rc.exe), using the following at a command prompt:

set include=C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include
rc DotNetSMTP.rc

The result is a file called DotNetSMTP.res that we need to pass to the .NET C# compiler using the /win32res option to instruct it to add it to the assembly. Unfortunately, there's no place in the VS IDE to specify this, so what we do instead is create a one-line batch file that does the compile for us. Simply create a build.cmd file with the following command in it:

csc /t:library /out:<directory>\DotNetSMTP.dll /win32res:DotNetSMTP.res DotNetSMTP.cs

The <directory> isn't literal. You put the directory that you want the compiled assembly stored in there (e.g., bin/Debug).

Note that the Genman32 isn't only capable of generating the manifest file for you; it can also embed it directly in the assembly as well.


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

Can you tell me how can I deploy it to the client' pc?


Your Feedback
Leo wrote: Can you tell me how can I deploy it to the client' pc?
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