Announcing IronCOM -- harness .NET power via COM automation

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx, program-l@xxxxxxxxxxxxx
  • Date: Wed, 24 Oct 2007 06:34:26 -0400 (EDT)

Now available at
http://www.EmpowermentZone.com/comsetup.exe

IronCOM
Version 1.0
October 24, 2007
Copyright 2007 by Jamal Mazrui
MIT License

Contents

Description
Installation
Examples
Development Notes
----------

Description

COM (Component Object Model) is a binary standard that permits programs
developed in different languages to interoperate and serve one another
with specialized functionality.  IronCOM is an open source COM server that
offers access to much of the .NET Framework 2.0 Class Library:  an
organized collection of thousands of classes, methods, properties, and
other members, which has been developed by Microsoft as a successor to the
Win32 API (Application Programming Interface).  IronCOM is named in the
spirit of IronPython and IronRuby, bolstering a development approach with
the strength of the .NET Framework.

After installing IronCOM, a client program can instantiate it with the
"Iron.COM" ProgID (Program Identifier).  This object has a single,
powerful method called Eval.  It evaluates code in a language well-suited
for such scripting, Boo.  The language draws syntax from Python, and seeks
to combine the strengths of both static and dynamic typing as appropriate.

The code to be evaluated is a string containing any number of Boo
statements or expressions.  The Eval method returns a string that is the
result of the last expression evaluated.  Besides the code parameter of
the Eval method, four other strings are passed as parameters that the code
may reference.  Each is an empty string if not needed by the code.
----------

Installation

The IronCOM installer checks whether the .NET Framework is present on the
computer, and if not, prompts whether to obtain it from the Internet.  If
you restart Windows afterward, you also need to restart the IronCOM
installer.  It creates an IronCOM program group on the Windows Start Menu,
containing shortcuts to read documentation, navigate to the Boo web site,
or uninstall.

By default, the installer places files in the directory
C:\Program Files\IronCOM
The library is a .NET assembly called IronCOM.dll, which the installer
registers as a COM server and puts in the Global Assembly Cache for use by
any COM client on the computer.
----------

Examples

Here are some examples using the JAWS scripting language as a COM client.
They show tasks not possible by built-in functions of the language,
including the ability to invoke a Windows common dialog, download a file,
or make a Win32 API call at runtime.

Script TestIronCOM()
; Initial code for examples
Var
Object o, Object oNull,
String sCode, String s1, String s2, String s3, String s4,
String sDir, String sFile

SayString("Testing")
; Create IronCOM object
Let o = CreateObject("Iron.COM")

; Get the current directory of the active process
; Define Boo code to be evaluated
Let sCode = "System.IO.Directory.GetCurrentDirectory()"

; Evaluate code and display result
; Note that parameters s1 ... s4 are empty, since not needed
Let sDir = o.Eval(sCode, "", "", "", "")
MessageBox(sDir)

; Get a file name via the Windows open file dialog,
; prompting with a default name passed in the s1 parameter
; Note that the Windows forms namespace is imported
; Note that a line feed character seperates lines of Boo code
Let sCode = "import System.Windows.Forms\n"
Let sCode = sCode + "oDlg = OpenFileDialog()\n"
Let sCode = sCode + "oDlg.FileName = s1\n"
Let sCode = sCode + "oDlg.ShowDialog()\n"
Let sCode = sCode + "oDlg.FileName"

  ; Define the s1 parameter, doubling backslashes as required by JAWS
Script
Let s1 = "c:\\temp\\test.txt"

; Evaluate code and display result
Let sFile = o.Eval(sCode, s1, "", "", "")
MessageBox(sFile)

; Download a URL on the Internet to a file on disk
; Note that a namespace has to be imported
; from an assembly not examined by default
Let sCode = "import Microsoft.VisualBasic.Devices from
Microsoft.VisualBasic.dll\n"
Let sCode = sCode + "oNetwork = Network()\n"
Let sCode = sCode + "oNetwork.DownloadFile(s1, s2)"

; Define URL and file in s1 and s2 parameters
Let s1 = "http://www.EmpowermentZone.com/jfw90doc.zip";
Let s2 = "C:\\temp\\jfw90doc.zip"

; Evaluate code and display whether downloaded file exists
o.Eval(sCode, s1, s2, "", "")
MessageBox(IntToString(FileExists(s2)))

; Get short path name of file via Win32 API call
; Note that the main code is loaded from a file on disk
; which may be easier for debugging more complex snippets
Let sCode = "import Microsoft.VisualBasic.FileIO from
Microsoft.VisualBasic.dll\n"
Let sCode = sCode + "FileSystem.ReadAllText(s1)"
Let s1 = "C:\\Program Files\\IronCOM\\GetShortPath.boo"
Let sCode = o.Eval(sCode, s1, "", "", "")

; Now evaluate loaded code
Let s1 = "c:\\Program Files\\Internet Explorer\\iexplore.exe"
Let sFile = o.Eval(sCode, s1, "", "", "")
MessageBox(sFile)

; The Boo code that was loaded is shown below
; In communicating with the Windows API,
; note that a string data type is used to export the long path,
; a string builder is used to import the short path,
; and an integer is used to export the length of that buffer
; Note that the "pass" statement is indented, as required by Boo/Python
syntax

/* Content of the file GetShortPath.boo
import System
import System.Text
import System.Runtime.InteropServices

// Define Boo wrapper for Win32 function
[DllImport('kernel32.dll')]
def GetShortPathName(sLongPath as String, sShortPath as StringBuilder,
iLength as int):
  pass

// Call function and return result
sShortPath = StringBuilder(260)
GetShortPathName(s1, sShortPath, 260)
sShortPath.ToString().Trim()
*/ ; End of file content

Let o = oNull
EndScript

----------

Development Notes

Within the IronCOM program folder, the main source code is in the file
IronCOM.boo.  The library may be rebuilt with the batch file build.bat.
The installer may be rebuilt with the Inno Setup definition comsetup.iss.
Inno Setup is available from
http://innosetup.org

Several .NET components, used in development, are available from the
following web pages:

.NET Framework Version 2.0 Redistributable Package (x86)
http://www.microsoft.com/downloads/details.aspx?familyid=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en

.NET Framework 2.0 Software Development Kit (SDK) (x86)
http://www.microsoft.com/downloads/details.aspx?familyid=FE6F2099-B7B4-4F47-A244-C96D69C35DEC&displaylang=en

ILMerge
http://www.microsoft.com/downloads/details.aspx?FamilyID=22914587-b4ad-4eae-87cf-b14ae6a939b0&displaylang=en

Microsoft Component Installer Software Development Kit
http://www.microsoft.com/downloads/details.aspx?familyid=2A5E4EBC-651C-40AA-9525-1810AF47C317&displaylang=en

Resources for learning and programming in the Boo language are contained
in the subdirectory called Boo.  The Boo home page is at
http://boo.codehaus.org

I welcome feedback, which helps IronCOM improve over time.  When reporting
a problem, the more specifics the better, including steps to reproduce it,
if possible.

The latest version of IronCOM is available at the same URL,
http://www.EmpowermentZone.com/comsetup.exe

Jamal Mazrui
jamal@xxxxxxxxxxxxxxxxxxx

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts:

  • » Announcing IronCOM -- harness .NET power via COM automation