C++

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  StyleVision Server API > Code Examples >

C++

The example below shows how to use C++ code to generate an output RTF file using a PXF file and an input XML file. Ensure that StyleVision Server is installed and licensed and that it is available as a COM server object. Registration as a COM server object usually takes place during installation of StyleVision Server. To check if registration was successful, see About the COM Interface.

 

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

//

#include <iostream>

#include "atlbase.h"

 

// 32-bit StyleVision Server

#import "progid:StyleVision.Server"

// 64-bit StyleVision Server

//#import "progid:StyleVision_x64.Server"

 

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

{

 CoInitialize( NULL );

 

 try

 {

         StyleVisionServerLib::IServerPtr pSVS;

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

 

         //Set a working directory - used for output and for intermediate files

         pSVS->WorkingDirectory = "c:\\temp";

 

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

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

         //pSVS->ServerPath = "C:\\Program Files (x86)\\Altova\\StyleVisionServer2019\\bin\\StyleVisionServer.exe";

 

         //Prepare the name of the working XML

         pSVS->InputXML = "ExpReport.xml";

 

         //Add output paths (absolute or relative to WorkingDirectory) for all formats that should be generated

         pSVS->OutputRTF = "ExpReport.rtf";

 

         //Prepare the parameters, if your design uses parameters

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

 

         //Run the transformation; 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 (pSVS->Run("C:\\Program Files (x86)\\Altova\\StyleVisionServer2019\\etc\\Examples\\ExpReport.pxf"))

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

         else

                 std::cout << pSVS->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