Altova MapForce 2025 Enterprise Edition

This example shows how to create a sample C++ library and reference it in a MapForce Function File (.mff). The .mff file can then be imported as a MapForce library.

 

Configuration steps

To reference a C++ library in a .mff file, follow the instructions below.

 

Step 1. Create a header file

Create a header (.h) file for your class library. The following code listing illustrates a sample header file called Greetings.h.

 

#ifndef MYLIBRARY_GREETINGS_H_INCLUDED
#define MYLIBRARY_GREETINGS_H_INCLUDED
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
 
using namespace altova;
 
namespace mylib {
 
class ALTOVA_DECLSPECIFIER Greetings
{
  public:
   static string_type SayHello(bool isMorning);
};
 
} // namespace mylib
 
#endif // MYLIBRARY_GREETINGS_H_INCLUDED

 

Notice that the function is declared as static and that the namespace altova is imported. Remember to write ALTOVA_DECLSPECIFIER in front of the class name: this ensures that your classes will be compiled correctly—whether you use dynamic or static linkage in the generated code.

 

Step 2. Create a .cpp file

Create a .cpp file with the same name as the header file. The .cpp file must be in the same directory as the .h file. The following code listing illustrates a sample .cpp file called Greetings.cpp that includes the Greetings.h file created previously:

 

#include "StdAfx.h"
#include "../Altova/Altova.h"
#include "../Altova/AltovaException.h"
#include "../Altova/SchemaTypes.h"
 
#include "Greetings.h"
 
namespace mylib {
 
  string_type Greetings::SayHello(bool isMorning)
  {
     if( isMorning )        
        return _T("Good morning!");
     return _T("Good day!");
  }
}

 

Notice the lines that import StdAfx.h and several Altova libraries. These lines must be left unchanged. If the paths to the Altova libraries are correct in the generated code, these paths will point to the respective files. In contrast to Java or C#, you do not need to compile your source C++ files. They will be copied to the generated code and compiled with the rest of the generated mapping code.

 

Step 3. Create .mff and reference your C++ library

Using an XML editor, create a new .mff file and validate it against the following schema: C:\Program Files\MapForceLibraries\mff.xsd. Make sure that the namespace, function names and data types defined here correspond to those in the C++ code, as described in Configure .mff File. For information about data type support, see Data Type Mapping.

 

<?xml version="1.0" encoding="UTF-8"?>
<mapping version="9" library="mylib" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mff.xsd">
  <implementations>
     <implementation language="cpp">
        <setting name="namespace" value="mylib"/>
        <setting name="class" value="Greetings"/>
        <setting name="path" value="C:\Libraries\cpp"/>
        <setting name="include" value="Greetings.h"/>
        <setting name="source" value="Greetings.cpp"/>
     </implementation>
  </implementations>
  <group name="greetings">
     <component name="sayhello">
        <sources>
           <datapoint name="ismorning" type="xs:boolean"/>
        </sources>
        <targets>
           <datapoint name="result" type="xs:string"/>
        </targets>
        <implementations>
           <implementation language="cpp">
              <function name="SayHello"/>
           </implementation>
        </implementations>
        <description>
           <short>result = sayhello(ismorning)</short>
           <long>Returns "Good morning" or "Good day", depending on the input parameter.</long>
        </description>
     </component>
  </group>
</mapping>

 

Step 4. Import .mff as a library

Now that your custom library is referenced in the .mff file, you can import the .mff file into MapForce as a library. For more information, see Import .mff File.

 

C++ compiler errors

In order to execute mappings that use native C++ libraries, you will need to generate C++ code and run the mapping from your C++ code or application, as described in Generating C++ code. If you get a compiler error in #import "msado15.dll" rename("EOF", "EndOfFile"), modify the project properties to include a reference to msado15.dll in C:\Program Files\Common Files\System\ADO.

 

© 2018-2024 Altova GmbH