|
Comments
|
Today's Top SOA Links
.NET Calling .NET Components from PowerBuilder
Via COM Wrappers - Redux
By: Bruce Armstrong
Jul. 7, 2007 01:00 PM
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).
If you want further information on the details, I'd recommend the following resources:
Component Manifest 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"?> 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 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 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 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. Reader Feedback: Page 1 of 1
Your Feedback
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 |
||||||||||||||||||||||||||||||