How to Instantiate and Call a Commerce Interchange Pipeline Using C++

ID: Q199299


The information in this article applies to:


SUMMARY

The following sample code can be used to instantiate and call a Commerce Interchange Pipeline:


#include "windows.h"
#include "ole2.h"
#include "pipeline.h"
#include "commerce.h"
#include "initguid.h"
#include "mspu_guids.h"

HRESULT SampleExecutePipe( )
{

    HRESULT hr = S_OK;

    IPipeline*      pPipeline = NULL;
    IDictionary*    pRootDictionary = NULL;
    IDictionary*    pChildDictionary = NULL;
    IDispatch*      pdispChildDictionary = NULL;
    BSTR            bstrP = NULL;
    BSTR            bstrStringName = NULL;
    BSTR            bstrChildName = NULL;
    long            lErrors = 0;
    VARIANT         vChild;
    VARIANT         vString;
    VariantInit( &vChild );
    VariantInit( &vString );
    // build up the dictionary structure showing  a root dictionary
    //      containing a child dictionary
    //          containing a string to process
    // 
    // create the root
    // 
    hr = CoCreateInstance( CLSID_CDictionary, NULL, CLSCTX_INPROC_SERVER,
                            IID_IDictionary, (LPVOID*) &pRootDictionary);
    if (FAILED(hr)) goto Error;
    // create the child
    // 
    hr = CoCreateInstance( CLSID_CDictionary, NULL, CLSCTX_INPROC_SERVER,
                            IID_IDictionary, (LPVOID*) &pChildDictionary);
    if (FAILED(hr)) goto Error;
    // add the string to process to the child
    // 
    bstrStringName = SysAllocString( L"input_string" );
    // it will go here
    if (!bstrStringName) goto Error;
    bstrP = SysAllocString( L"Interesting text to process." );
    if (!bstrP) goto Error;
    vString.vt = VT_BSTR;
    vString.bstrVal = bstrP;
    hr = pChildDictionary->put_Value( bstrStringName, vString );
    // attach the child to the root -- as a IDispatch
    // 
    //hr = pChildDictionary->QueryInterface(IID_IDispatch,
    //                         (LPVOID*) &pdispChildDictionary);
    hr = pChildDictionary->QueryInterface(  IID_IUnknown,
                               (LPVOID*) &pdispChildDictionary);
    if (FAILED(hr)) goto Error;
    vChild.vt = VT_UNKNOWN | VT_BYREF;
    vChild.ppunkVal = &pdispChildDictionary;
    bstrChildName = SysAllocString( L"child_container" );
    // it will go here
    if (!bstrChildName) goto Error;
    hr = pRootDictionary->put_Value( bstrChildName, vChild );
    // create/load pipeline
    // 
    hr = CoCreateInstance( CLSID_CMtsPipeline, NULL, CLSCTX_INPROC_SERVER,
                         IID_IPipeline, (LPVOID*) &pPipeline);
    if (FAILED(hr)) goto Error;
    //ERROR
    //hr = pPipeline->LoadPipe( L"c:\filename.pcf" );
    hr = pPipeline->LoadPipe(bstrPipeFile);
    if (FAILED(hr)) goto Error;
    // process the root/child/string
    // 
    hr = pPipeline->Execute( 1, pRootDictionary, NULL, 0, &lErrors );

    if (FAILED(hr)) goto Error;
    if (lErrors > OPPERRORLEV_SUCCESS) hr = E_FAIL;
    // consume the results -- stored in the root dictionary here
    // 
  Error:

    if (bstrP) pChildDictionary->Release();
    if (pdispChildDictionary) pdispChildDictionary->Release();
    if (pChildDictionary) pChildDictionary->Release();
    if (pRootDictionary) pRootDictionary->Release();
    if (pPipeline) pPipeline->Release();
    if (bstrP) SysFreeString( bstrP );
    if (bstrStringName) SysFreeString( bstrStringName );
    if (bstrChildName) SysFreeString( bstrChildName );
    return hr;
} 


MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.

Additional query words:


Keywords          : sitesrv3faq 
Version           : winnt:3.0
Platform          : winnt 
Issue type        : kbhowto 

Last Reviewed: May 3, 1999