This example uses the Visual Studio 2010 IDE. To begin, generate C++ code from the DB_CompletePO sample mapping available in the <Documents>\Altova\MapForce2023\MapForceExamples\ directory, and then open the solution in Visual Studio.
By default, the name of the solution file is Mapping.sln, and it is located in the Mapping subdirectory relative to the directory where you saved the generated code. If you changed the application name from the mapping settings, then the name of the .sln file is changed accordingly. For example, if you changed the application name to MyApplication, then the solution file is called MyApplication.sln, and it is located in the MyApplication subdirectory.
Sample C++ solution generated with MapForce
Open the Mapping.cpp file, and locate the _tmain method. The following code sample illustrates an extract from this method. The mapping sources and targets are defined as parameters to the Run method. Since this mapping reads data from a database, there is also an input parameter which is a database connection string. If necessary, you can modify the connection string of the database.
Note that the file paths in the code below have been changed from absolute to relative.
To define custom mapping source or target files:
•Locate the parameters passed to the Run method and edit them as required. In the code sample above, the mapping input is a connection string to the CustomersAndArticles.mdb database and _T("ShortPO.xml"). The mapping output is _T("CompletePO.xml").
To add extra error handling code:
•Edit the code below the catch (CAltovaException& e) code.