///////////////////////////////////////////////////////////////////// // OuterComponent.cpp - Accepts a string from client, creates an // // InnerComponent, sends it a string for // // modification, then modifies the returned // // string before sending back to its client. // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 2007 // ///////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "OuterComponent.h" #include "..\InnerComp\InnerComp.h" //----< modifiy client's string, then send to InnerComponent >------- STDMETHODIMP COuterComponent::SendStringForModification(BSTR* str) { ////////////////////////////////////////////////////////////////// // HRESULT hr = pInner.CoCreateInstance(CLSID_InnerComponent); // called in COuterComponent constructor // modify client's string CComBSTR s(*str); // convert from BSTR to wrapped BSTR s += L"\n Hi from OuterComp"; // add another modification to client's string BSTR stri = s.Detach(); // convert back to BSTR if(pInner != 0) { pInner->ModifyStringAgain(&stri); } *str = stri; return S_OK; } //----< return InnerComponent pointer, created in constructor >------ STDMETHODIMP COuterComponent::ReturnInnerPtr(IInnerComponent** pInnerPtr) { *pInnerPtr = pInner; (*pInnerPtr)->AddRef(); // client should release return S_OK; }