Please enable JavaScript to view this site.

Altova MapForce Server 2020 Advanced Edition

The following example illustrates how to run a mapping execution file (.mfx) from C++ code. On Windows, the example files are available at the following path: C:\Program Files\Altova\MapForceServer2020\etc\Examples.

 

Before running the code below, ensure the following prerequisites are met:

 

MapForce Server is installed and licensed

MapForce Server is available as a COM server object (normally, this process takes place automatically during MapForce Server installation; to check if registration was successful, see About the COM Interface).

 

// MapForceServerAPI_sample.cpp : Defines the entry point for the console application.

//

#include <iostream>

#include "atlbase.h"

 

 

// 32-bit MapForce Server

#import "progid:MapForce.Server"

// 64-bit MapForce Server

// #import "progid:MapForce_x64.Server"

 

int _tmain(int argc, _TCHAR* argv[])

{

 CoInitialize( NULL );

 

 try

 {

         //Create a MapForce Server object

         MapForceServerLib::IServerPtr pMFS;

         CoCreateInstance( __uuidof( MapForceServerLib::Server ), NULL, CLSCTX_ALL, __uuidof( MapForceServerLib::IServer ), reinterpret_cast< void** >( &pMFS ) );

 

         //Set a working directory - used as a base for relative paths (you may need to adapt the path to the installation folder)

         pMFS->WorkingDirectory = "C:\\Program Files (x86)\\Altova\\MapForceServer2020\\etc\\Examples";

 

         //Default path to the MapForce Server executable is the installation path (same dir with the MapForceServer.dll)

         //In case you moved the binaries on the disk, you need to explicitly set the path to the .exe file

         //pMFS->ServerPath = "C:\\Program Files (x86)\\Altova\\MapForceServer2020\\bin\\MapForceServer.exe";

 

         //Set global resource file and configuration, if your mapping uses global resources

         //pMFS->SetOption( "globalresourcefile", "GlobalResource.xml" ); // "gr" can be used as short name for "globalresourcefile"

         //pMFS->SetOption( "globalresourceconfig", "Default" ); // "gc" can be used as short name for "globalresourceconfig"

 

         //Prepare the parameters, if your mapping uses parameters

         //pMFS->AddParameter( "testparam1", "value 1" );

 

         //Run the mapping; the output will be stored at C:\temp\ExpReport.rtf

         // NOTE Please adapt the path to the input file in order to run the sample

         if (pMFS->Run("C:\\Program Files (x86)\\Altova\\MapForceServer2020\\etc\\Examples\\TokenizeString.mfx"))

                 std::cout << "Success - finished execution" << std::endl;

         else

                 std::cout << pMFS->LastExecutionMessage << std::endl;

 

 }

 catch (_com_error& err )

 {

         BSTR  bstrMessage;

         (err).ErrorInfo()->GetDescription( &bstrMessage );

         std::cout << "Exception occurred: " << _com_util::ConvertBSTRToString( bstrMessage ) << std::endl;

 

 }

 

 CoUninitialize();

 return 0;

}

© 2019 Altova GmbH