Visual C++
This Visual C++ code example demonstrates how to create the connector and how to create a business function on the COM server. This example creates an AddressBook business function and uses GenCOM objects from C++.
#include <windows.h>
#include <stdio.h>
#include <objbase.h>
#include <comdef.h>
#include <wchar.h>
#include addressbook.h
#include AddressBook_i.c
#include jdecomconnector2.h
#include jdecomconnector2_i.c
#define IPhone ID0100032
#define IMailing ID0100031
#define IAddress ID0100033
#define IEffectiveDate ID0100019
#define IParentAddress ID0100381
#define SERVER OLESTR("COMSRV") //Change to the COM server.
#define ABNO 4242 //change this according to user input.
HRESULT CreateConnector( IConnector **ppConnector )
{
HRESULT hr = E_FAIL;
*ppConnector = 0;
//NOTE: Pass a COSERVERINFO struct to activate on a remote machine
COSERVERINFO csi = {0, SERVER, 0, 0};
MULTI_QI mqi = { &IID_IConnector, 0, 0 };
hr = CoCreateInstanceEx(CLSID_Connector, 0, CLSCTX_LOCAL_SERVER,
0, // &csi,
1, &mqi);
if(SUCCEEDED(hr) && SUCCEEDED(mqi.hr))
{
ppConnector = reinterpret_cast<IConnector*>(mqi.pItf);
}
return hr;
}
HRESULT Login( IConnector **pConnector, IOneWorldInterface **ow,
long *accessno )
{
HRESULT hr;
IDispatch *idsptch = 0;
printf("Login started\n");
bstr_t User(L "Foo "), PassWord(L"Bar "), Env("DV9NIS2");
hr = (*pConnector)->Login(User,PassWord,Env,accessno );
if( !SUCCEEDED(hr))
{
printf( "Login failed with hr = %x",hr);
return E_FAIL;
}
_bstr_t bo("OneWorld_FunctionHelper.1");
hr=(*pConnector)->CreateBusinessObject(bo, *accessno, &idsptch );
if( !SUCCEEDED(hr)||(!ow))
{
Printf("CreateBusinessObject(OneWorld.FunctionHelper.1) failed
with hr %x",hr);
return E_FAIL;
}
hr=idsptch->QueryInterface(IID_IOneWorldInterface, (void **)ow );
if(!SUCCEEDED(hr)||(!ow))
{
Printf( QueryInterface for IOneWorldInterface failed with hr "%x",hr);
return E_FAIL
}
printf("Login completed \n");
return S_OK;
}
HRESULT UseAddressBook(IConnector *pConnector, IOneWorldInterface
*ow, long*accessno)
{
HRESULT hr;
IJDEAddressBook *ab;
IDispatch *idsptch;
IPhone *phone;
IMailing *Mailing;
IAddress *Address;
IEffectiveDate *EffectiveDate;
IParentAddress ParentAddress;
printf("Starting to use AddressBook\n");
_bstr_t bo("AddressBook.JDEAddressBook");
hr = pConnector->CreateBusinessObject(bo, *accessno, &idsptch);
hr = idsptch->QueryInterface( IID_IJDEAddressBook, (void **&ab);
if(!SUCCEEDED(hr)||(tab))
{
printf( "CreateBusinessObject( AddressBook ) has failed with hr %x",
hr);
return E_FAIL;
}
return S_OK;
}
This code creates the connector object and uses it to create a business function with its associated ParameterSet. The code then calls a method, Foo1, on the business object with the ParameterSet, the connector, and the access code returned by the act of logging on to the connector.
Int main(int argc, char *argv[])
{
HRESULT hr;
IOneWorldInterface *ow;
long accessno;
IConnector *pConnector;
hr - CoInitializeEx(0, COINIT_MULTITHREADED);
if(SUCCEEDED(hr))
(
hr = CreateConnector(&pConnector);
if(SUCCEEDED(hr))
{
Login( &pConnector, &ow, &accessno );
//Do more processing with AddressBook and logoff at the end.
}
CoUninitialize();
}