Article ID: 199299
Article Last Modified on 7/18/2001
#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;
}
Keywords: kbhowto kbfaq KB199299