Accessing the API Print this Topic Previous Page Up One Level Next page

Home >  The MapForce API > Overview >

Accessing the API

To access the MapForce COM API, a new instance of the Application object must be created in your application (or script). Once this object is created, you can interact with MapForce by invoking its methods and properties as required (for example, create a new document, open an existing document, generate mapping code, etc).



To make the MapForce COM object available in your Visual Studio project, add a reference to the MapForce type library (.tlb) file. The following instructions are applicable to Visual Studio 2013, but are similar in other Visual Studio versions:


1.On the Project menu, click Add Reference.
2.Click Browse and select the MapForce.tlb file located in the MapForce installation folder.


A sample MapForce API client in C# is available at: (My) Documents\Altova\MapForce2019\MapForceExamples\API\C#.


In Java, the MapForce API is available through Java-COM bridge libraries. These libraries are available in the MapForce installation folder: C:\Program Files (x86)\Altova\MapForce2019\JavaAPI (note this path is valid when 32-bit MapForce runs on 64-bit Windows, otherwise adjust the path accordingly).


AltovaAutomation.dll: a JNI wrapper for Altova automation servers
AltovaAutomation.jar: Java classes to access Altova automation servers
MapForceAPI.jar: Java classes that wrap the MapForce automation interface a Javadoc file containing help documentation for the Java API


To allow access to the MapForce automation server directly from Java code, the libraries above must be in the Java classpath.


A sample MapForce API client in Java is available at: (My) Documents\Altova\MapForce2019\MapForceExamples\API\Java.


In scripting languages such as JScript or VBScript, the MapForce COM object is accessible through the Microsoft Windows Script Host (see Such scripts can be written with a text editor, and do not need compilation, since they are executed by the Windows Script Host packaged with Windows. (To check that the Windows Script Host is running, type wscript.exe /? at the command prompt). A sample MapForce API client in JScript is available at: (My) Documents\Altova\MapForce2019\MapForceExamples\API\JScript.


Note:For 32-bit MapForce, the registered name, or programmatic identifier (ProgId) of the COM object is MapForce.Application. For 64-bit MapForce, the name is MapForce_x64.Application.



The following guidelines should be considered in your client code:


Do not hold references to objects in memory longer than you need them. If a user interacts between two calls of your client, then there is no guarantee that these references are still valid.
Be aware that if your client code crashes, instances of MapForce may still remain in the system. For details on how to avoid error messages, see Error handling.
Free references explicitly, if using languages such as C++.


Creating the Application object

The syntax to create the starting Application object depends on the programming language, as shown in the examples below:



Visual Basic

Dim objMapForce As MapForceLib.Application = New MapForceLib.Application




' Create a new instance of MapForce.
Dim objMapForce As Application
Set objMapForce = CreateObject("MapForce.Application")




' Access a running instance, or create a new instance of MapForce.
Set objMapForce = GetObject("MapForce.Application");




// Create a new instance of MapForce via its automation interface.
MapForceLib.Application objMapForce = new MapForceLib.Application();




// Start MapForce as COM server.
com.altova.automation.MapForce.Application objMapForce = new Application();
// COM servers start up invisible so we make it visible




// Access a running instance, or create a new instance of MapForce.



 objMapForce = WScript.GetObject ("", "MapForce.Application");

 // unhide application if it is a new instance

 objMapForce.Visible = true;


catch(err) { WScript.Echo ("Can't access or create MapForce.Application"); }

© 2019 Altova GmbH