C++
L'exemple ci-dessous montre comment utiliser le code C++ pour générer un fichier de sortie RTF à l'aide d'un fichier PXF et d'un fichier XML d'entrée Assurez-vous que StyleVision Server est installé et mis sous licence et qu'il est disponible en tant qu'objet de serveur COM L'enregistrement en tant qu'un objet de serveur COM a généralement lieu pendant l'installation de StyleVision Server. Pour vérifier que l'enregistrement a réussi, voir A propos de l’interface COM. Voir aussi A propos de l’interface .NET.
// StyleVisionServerAPI_Sample.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include "atlbase.h"
// The following import statements require the corresponding C++ tool-chain to be selected in the project configuration file.
#ifndef _WIN64
// 32-bit StyleVisionServer
#import "progid:StyleVision.Server"
#else
// 64-bit StyleVisionServer
#import "progid:StyleVision_x64.Server"
#endif
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize( NULL );
try
{
//Create a StyleVision Server object
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 = ".."; // this is relative to this applications' working directory (the project folder)
//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\\StyleVisionServer2025\\bin\\StyleVisionServer.exe";
//pSVS->ServerPath = "C:\\Program Files\\Altova\\StyleVisionServer2025\\bin\\StyleVisionServer.exe";
//Prepare the name of the working XML
// This can be an absolute/relative path if the file is stored externally (not inside PXF)
// pSVS->InputXML = "ExpReport.xml";
// Or it can contain the path INSIDE the PXF
// pSVS->InputXML = "ExpReport.pxf|zip\\ExpReport.xml";
// Easiest way is to refer to the file as being embedded in the transformation file
pSVS->InputXML = "altova://packagedfile/ExpReport.xml";
//Add output paths (absolute or relative to WorkingDirectory) for all formats that should be generated
pSVS->OutputRTF = "ExpReport.rtf";
pSVS->OutputPDF = "ExpReport.pdfrtf";
pSVS->OutputHTML = "ExpReport.html";
//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->Generate("ExpReport.pxf"))
{
std::cout << pSVS->LastExecutionMessage << std::endl;
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;
}