///////////////////////////////////////////////////////////////////// // OuterComponent.h - 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 // ///////////////////////////////////////////////////////////////////// /* * When you build this component after runing MIDL compiler you will get * an error that one of the generated files can't find InnerComp.h. * You have to change the offending include from * #include InnerComp.h * To * #include "..\InnerComp\InnerComp.h" * Just like the include below. That is caused by a bug in the * code generator part of MIDL compiler. */ #pragma once #include "resource.h" // main symbols #include "OuterComp.h" #include "..\InnerComp\InnerComp.h" // COuterComponent class ATL_NO_VTABLE COuterComponent : public CComObjectRootEx, public CComCoClass, public IDispatchImpl { public: COuterComponent() { HRESULT hr = pInner.CoCreateInstance(CLSID_InnerComponent); } DECLARE_REGISTRY_RESOURCEID(IDR_OUTERCOMPONENT) BEGIN_COM_MAP(COuterComponent) COM_INTERFACE_ENTRY(IOuterComponent) COM_INTERFACE_ENTRY(IDispatch) END_COM_MAP() DECLARE_PROTECT_FINAL_CONSTRUCT() HRESULT FinalConstruct() { return S_OK; } void FinalRelease() { } public: STDMETHOD(SendStringForModification)(BSTR* str); STDMETHOD(ReturnInnerPtr)(IInnerComponent** InnerPtr); private: ///////////////////////////////////////////////// // Interface pointer wrapper that will hold onto // a pointer to the InnerComponent's interface // for the lifetime of the OuterComponent CComQIPtr pInner; }; OBJECT_ENTRY_AUTO(__uuidof(OuterComponent), COuterComponent)