Difference between revisions of "DOT NET Interface Library/en"

From expecco Wiki (Version 2.x)
Jump to navigation Jump to search
Line 19: Line 19:
or (in JavaScript):
or (in JavaScript):
dotNetHandle = DOTNET::DotNet.startNew();
dotNetHandle = DOTNET::DotNet.newWithServer();

Revision as of 14:47, 8 November 2019


The .NET Interface Library (".NET Bridge") contains a mechanism to access Microsoft .NET (CLR) objects of a local or remote .NET application (a so-called .NET bridge), and an API for elementary blocks and a library of blocks to interact with these objects.

Programmatic Interface[edit]

Access to .NET objects, classes and programs is done via a framework called "dotNET-Bridge". This framework implements transparent forwarding of expecco messages (virtual function calls) from either Smalltalk or JavaScript code to .NET objects as existent in a local or remote .NET virtual machine. Also, return values, callBacks and exception information are passed back from the .NET program to expecco. A proxy-object mechanism which catches all function calls, wraps the arguments and sends a datagram to the other bridge side is used for this to be almost completely transparent to the Smalltalk/JavaScript code inside expecco.

In addition to existing blocks of the .NET Interface Library, programmatic access to dotNET objects is sometimes useful or required. So the following information is useful if you want to write your own elementary .NET-blocks, or if you have to enhance the existing library by adding application-specific interface blocks.

Initializing / Releasing the Bridge[edit]

Before any communication can take place between expecco and any dotNet object, the .NET side of the bridge has to be started, and a communication path to be setup. All of the bridges classes are in the DOTNET namespace; the main interface class is DotNet, in this namespace:

    dotNetHandle := DOTNET::DotNet startNew.

or (in JavaScript):

    dotNetHandle = DOTNET::DotNet.newWithServer();

This starts the .NET-side of the bridge (the executable named "DotNetBridge.Server.exe"), and waits for a connection request from this program.

When finished, release the bridge with:


which shuts down the connection and terminates the executable.

Loading Assemblies[edit]

Using the "loadLibrary"-function, well-known assemblies can be loaded:




Arbitrary files which contain assemblies are loaded with:


Accessing Globals[edit]

Globals, nameSpaces and members of a namespace are accessed using message sends to the dotNet handle, where the message name is the name of the global, namespace or interface. These messages can be chained, to access a hierarchy of namespaces. For example:


Instantiating a Class[edit]

Object instances are created via the "new"-message, sent to a global:

    b = dotNetHandle.Button.new();
    f = dotNetHandle.Form.new();

once instantiated, any message can be sent transparently to such an .NET object, as if it was an expecco object:

    b.text("Hello World");


Callbacks from .NET back into expecco are implemented via Smalltalk blocks (JavaScript anonymous functions). The bridge automatically installs an appropriate callback, whenever a block/function is given to a .NET component as a callback or hook.

Here is a complete example for creating a .NET form with a callback into expecco. This code could be put into an EB (Elementary Block) of an expecco activity diagram:

    var dotNet, form, button;

    // called when the .NET button is clicked
    function callBack() { 
        dotNet.MessageBox.show("Hello from expecco"); 

    dotNet = DOTNET::DotNet.startNew();
    button = dotNet.Button.new();
    button.click.add( callBack );
    form = dotNet.Form.new();
    button.dock( dotNet.DockStyle.fill );
    form.controls.add( button );


Calling ActiveX/COM Objects[edit]

It's possible to make calls to ActiveX/COM Objects through the bridge.

To do this, you need to create a dotNet Assembly with the types from a .tlb or .ocx file.

This can be done with the tlbimp utility which is part of VisualStudio (reachable through the VS Dev CMD Shell...)

In this shell, you can e.g. execute

tlbimp c:\windows\system32\wshom.ocx   

which will create a file called IWshRuntimeLibrary.dll for the Windows Script Host Runtime Library in the current directory. This can then be used to automate the Windows Script Host Runtime Library Object.

Here an example how to use this in code:

  |dotNet shell buttonPressed|

    dotNet := DotNet singletonInstance.
    dotNet loadFile:'C:\Temp\IWshRuntimeLibrary.dll'.
    shell := dotNet WshShellClass new.
    buttonPressed := shell popup:'Hello from Micha' secToWait:15 title:'.NET Bridge Com Demo' type:0.
    buttonPressed inspect                        

to be continued

See Also[edit]

The Java Interface Plugin & Library, which implements a likewise interface for Java applications/libraries.

Back to Plugins
Back to Online Documentation.

Copyright © 2014-2020 eXept Software AG