Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


November 1998

Perl COM Objects


RSS
Subscribe to Windows IT Pro | See More OLE DB Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here
Download the Code Here
Download the Code Here

Step 3: Define and Expose the Object's Methods and Properties
The most delicate step in the process is editing the %TypeLib hash. You use the %TypeLib hash to express the aspects of your implementation that you want to expose to the outside world. What makes this step so delicate is that the %TypeLib hash is a complex data structure. Fortunately, you need to be concerned about only these few implementation aspects:

  • PackageName, the name of the package
  • ControlName, a friendly, possibly more descriptive name for the control
  • ControlVer, the control's version number
  • ProgID, the name you use to create instances of the object in other programming environments
  • DefaultMethod, the control's default method
  • Methods, a hash for each method the control exposes that contains keys describing the method's return type, total number of parameters, number of optional parameters, and parameter type
  • Properties, a hash for each property the control exposes that contains keys describing the property type and whether users can change the property

Listing 2 contains the edited %TypeLib hash. 'SysLog' is the PackageName, 'SysLog Control' is the ControlName, 1 is the ControlVer, 'SysLog' is the ProgID, and 'Write' is the DefaultMethod. Callout B in Listing 2 shows the Write method that the control will use. Notice that you must define the variable types as variants in the Properties section that follows the Write method. In COM and Object Linking and Embedding (OLE) automation, variants are the data types. Variants provide the mechanism for weakly typed programming environments (e.g., ASP, Perl, VBA, and WSH) to appropriately translate data. Table 1 lists the variant data types.

Step 4: Build the .dll File
After you've finished defining and developing your control, you can build it. To invoke the build process, you run PerlCtrl.exe, passing it the control's source and TypeLib filename by typing

C:\Perl\Source\Controls>perlctrl SysLog.pl

The build process first checks the syntax of the source file. If everything is OK, PerlCtrl creates the .dll file, as the following console messages indicate:

SysLog.pl syntax OK
Creating PerlCtrl SysLog.dll...all done.

Step 5: Register the .dll File
As is the case with most ActiveX controls, you must register your control before you can use it. You can use NT's regsvr32.exe utility to complete this task. Run regsvr32.exe, passing it the name of the .dll file to register by typing

C:\Perl\Source\Controls>regsvr32 SysLog.dll

You can get additional help on how to use this utility by running the command without arguments. If the registration succeeds, a message box displays the message DLLRegisterServer in SysLog.dll succeeded.

Step 6: Use the Control
The final step is to use the control. Listing 3, page 196, contains a short WSH VBScript example that uses the SysLog control.

The example script begins by declaring two variables, oSysLog and sProps. Next, the script creates a new SysLog object using CreateObject, which specifies the ProgID you defined in the %TypeLib hash. After creating the object, the script retrieves the object's default properties and displays them using VBScript's MsgBox function. The script then changes the properties and displays them a second time. Finally, the script invokes the object's Write method to enter information in the NT Application Log. When the script is done with the object, it uses VBScript's Nothing keyword to release the object.

Room for Improvement
PerlCtrl's online Help points out several limitations, including the ability to expose only one object per .dll file, the lack of support for automation events, and the lack of AutoComplete support in the VB development environment. According to ActiveState, a future release will address these limitations.

I encountered another obstacle that could potentially limit PerlCtrl's use. In my tests, I was unable to use PerlCtrl components on those machines I didn't install Perl on. I hope that ActiveState will address this limitation in its next version.

I also encourage ActiveState to provide a wizard that people can use to fill in the %TypeLib hash. A wizard would not only minimize programmer error, but also put the PerlCtrl development environment on par with other visual development systems. Providing that ActiveState addresses these limitations, I think PerlCtrl has the potential to elevate Perl to the level of reusable COM-based component software.

New Scripting Newsletter
Windows NT Magazine is launching Win32 Scripting Journal, a 16-page scripting and task-automation newsletter for Windows NT and Win95 system administrators. For more information, visit the Web site at http://www.winntmag.com/ newsletter/scripting.

End of Article

   Previous  1  [2]  Next  


Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...


Related Articles Inside the New Perl Resource Kit

Task Automation Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

The Easiest Way to Save Time and Money on E-mail and SharePoint Management

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement