Unmanaged C++ Example

Include the following headers:

#include "stdafx.h"
#include <atlstr.h> // This is for the atl types

Add references to the following libraries and namespace reference

#import <NGSystem.tlb> no_namespace
#import <GenericClass.dll> no_namespace
using namespace std;

Define main method

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

Define the ISegmentCycle COM interface pointer and create an instance of the segment component. In this case we are connecting to the SAMPLE.1 Component (the business segment of SAMPLE application)

CComPtr<ISegmentCycle> pSegment; 
HRESULT hr = ::CoInitialize(NULL); // initialise COM libraries     
hr = pSegment.CoCreateInstance(L"SAMPLE.1" );

Establish a session

long Sessid = pSegment->Connect(NULL, FALSE, FALSE);

Declare IIspecCycle interface pointers and call CreateInstance(). Here we are adding a Sales Rep to SAMPLE:

CComPtr<IIspecCycle> pInput, pOutput; pInput = CComQIPtr<IIspecCycle>(pSegment->CreateInstance(Sessid, L"SREP"));

Set values in ispec fields and process the transaction:

pInput->SetValue( L"_UserMAINT", L"ADD"); pInput->SetValue( L"AREA", L"Asia"); pInput->SetValue( L"NAM", L"John Smith"); pInput->SetValue( L"SALESREP", L"1");

Retrieve output in the output interface pointer from the ProcessMsg call

pOutput = CComQIPtr<IIspecCycle>(pSegment->ProcessMsg( Sessid, pInput ));

Use the output interface pointer as the next input interface pointer to ensure transaction ID is correct

pInput = pOutput;

Process another transaction to retrieve the Sales Rep just entered

pInput->SetValue( L"_UserMAINT", L"INQ"); 
pInput->SetValue( L"SALESREP", L"1"); 
pOutput = CComQIPtr<IIspecCycle>(pSegment->ProcessMsg( Sessid, pInput ));
std::cout << pOutput->GetValue( L"NAM" ); // Display entered Sales Rep on command line 
}

Disconnect the session

pSegment->Disconnect(Sessid);