Accessing the .NET Framework from Interix


Code and scripts ported to the Interix environment within Windows fall into the unmanaged code category of the Microsoft .NET Framework. However, it is still possible to provide interoperability for such an application under .NET. There are two ways of doing this:

  • Encapsulate as COM components Interix-based applications written in C, C++, VBScript, JScript, or even the Korn and C shells .

  • Run a program based on the Microsoft Win32 application programming interface from a shell script within Interix.

The following sections discuss these options.

Encapsulation Using COM

To access Interix-based application functionality from a Win32-based application, define and develop a COM wrapper to provide Interix application functionality as a set of COM interfaces. The Win32-based application can call these interfaces to access services from the Interix application.

For example, consider an application that obtains its input from command-line options and provides its output to standard output (STDOUT). A COM interface can use IDL to pass the standard output information to a Win32-based application (such as a C++ application, Visual Basic application, or Microsoft Excel spreadsheet) or script (such as VBScript). The Win32 client makes a call to the Interix-based application COM DLL wrapper. The DLL invokes Posix.exe (and therefore, the Interix subsystem) to run the Interix “based application with the command-line options. The COM DLL captures and interprets the output and passes it back to the Win32-based application through the COM interface.

To build the application DLL library by encapsulating the application, follow these steps:

  1. Define the COM interface by using IDL. Because the COM object needs to be usable from scripting applications such as VBScript and JavaScript, the interface needs to support ActiveX automation; that is, make use of IDispatch::Invoke as well as the custom interface.

  2. Implement the interface in the DLL. Invoke Posix.exe to run the Interix-based application, capture the standard output, and then pass that data to the caller of the interface.

    Make sure the application command line is correct for Posix.exe. For example, it might require careful consideration of command-line quoting.

  3. Build the DLL.

For more information about encapsulation of Interix-based applications in COM objects, see the Services for UNIX 3.0 Technical Note, Interix and COM.

After a COM interface has been added to the unmanaged code ” in this case, the UNIX application ported to Interix ” it can then interoperate with the .NET managed code by using the COM Interop feature of the Microsoft .NET Framework.

Chaining Commands and Scripts from Web Services

In the Interix environment, Win32-based programs can be run from the Korn and C shells by using the SFU runwin32 command. The Interix environment also includes shell scripts to invoke the standard Windows command-line programs; Cmd.exe built-ins are provided in the directory /usr/ contrib /win32/bin.

Visual Studio .NET and the Microsoft .NET Framework also include support for ECMA Script (Java Script) and VBScript. The fact that the compiler compiles scripts into Intermediate Language does not change the way that Interix interacts with the Win32 environment to launch and chain commands and scripts.




UNIX Application Migration Guide
Unix Application Migration Guide (Patterns & Practices)
ISBN: 0735618380
EAN: 2147483647
Year: 2003
Pages: 134

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net