八. com 跨进程特性

Click here to load reader

Upload: lynne

Post on 28-Jan-2016

147 views

Category:

Documents


0 download

DESCRIPTION

八. COM 跨进程特性. 进程外组件 进程内 COM 对象的缺陷 进程外组件的使用 列集 列集的概念 接口指针的列集 标准列集过程 总体结构 存根 代理 接口列集器 ORPC 通道 标准列集的实现 自定义列集 IMarshal 接口 例子. 1.进程外组件. 1.1 进程内 COM 对象的缺陷 1.缺乏错误隔离. 对象的运行时错误将直接引起客户程序的崩溃. 2.安全环境共享 - PowerPoint PPT Presentation

TRANSCRIPT

  • . COM

    COM ORPCIMarshal

  • 1.1.1 COM1.. . 2. ,. ; ,. 3. .COMDCOM.(.) (,,),.COM.

  • 1.2 COMexe.. DllRegisterServer DllUnregisterServer. ,/ RegServer/UnregServer, (). COMLocalServer32InprocServer32.DllGetClassObject,CoGetClassObject:CoGetClassObjectEXE, ...(/Embedding)CoInitializeCoRegisterClassObjectCOM.,,.DllCanUnloadNow. . ,CoRevokeClassObjectCOM. CoRegisterClassObject CoRevokeClassObject,COM.RPC.:

  • 2. RPC. . RPC. RPCRPC, ORPC. ORPC, . .

  • 2.1 (marshaling) (unmarshaling)marshal,:: 32, .: . ,,,,.: ... .

  • 2.2 ,. ( Apartment , ):.,,COM, ,. ,... :

  • OXID(). OXIDIPC(),. OXIDOXID(OXID Resolver, OR). ORRPCSS.COMCoMarshalInterface:

  • HRESULT CoMarshalInterface( IStream *pStm, //,.,,. . REFIID riid, // IUnknown *pUnk, //,riid. DWORD dwDestContext, //. void *long pvDestContext, //. DWORD mshlflags //(,));CoUnmarshalInterfaceHRESULT CoUnmarshalInterface( IStream *pStm, //REFIID riid, // void * * ppvObj //);,(),,.

  • 3 3.1

    IMarshal,.: COMORPC (Object Remote Procedure Call). COMMS RPCORPC ORPCRPCCOMORPCNDRNetwork Data RepresentationCORBACDR Common Data RepresentationWebXML:

  • proxystub

  • 3.2 CoMarshalInterface, COM: . (Stub Manager). COM, OID(). COM..ORPC.COM(interface stub).IPID. ,ORPC[in],,HRESULT[out]ORPC. COM.

  • IRpcStubBufferclass IRpcStubBuffer : public IUnknown { HRESULT Connect(IUnknown *pUnkServer) = 0; //COM void Disconnect() = 0; // HRESULT Invoke(RPCOLEMESSAGE *pMessage, IRpcChannelBuffer *pChannel) = 0;//ORPC,COMInvoke, *pMessage[in],RPC IRPCStubBuffer* IsIIDSupported(REFIID iid) = 0; ULONG CountRefs() = 0; HRESULT DebugServerQueryInterface(void **ppv) = 0; void DebugServerRelease(void *pv) = 0;};

  • 3.3 CoUnmarshalInterface,(proxy manager). ,COM,(Interface proxy),.. IUnkown.AddRefRelease,,..ORPC([in]).ORPC[out]HRESULT,.

  • IRpcProxyBuffer.class IRpcProxyBuffer : public IUnknown {HRESULT Connect(IRpcChannelBuffer *pRpcChannelBuffer) = 0; void Disconnect() = 0;};

    RPCConnectRPCIRpcChannelBufferGetBufferSendReceive

  • 3.4 .CLSID. (Interface marshaler). IClassFactory (CreateInstance,COM) ,, IPSFactoryBuffer.[ uuid(D5F569D0-593B-101A-B569-08002B2DBF7A),local,object ] interface IPSFactoryBuffer : IUnknown { HRESULT CreateProxy( [in] IUnknown *pUnkOuter, // [in] REFIID riid, //IID [out] IRpcProxyBuffer **ppProxy, // [out] void **ppv ); // HRESULT CreateStub( [in] REFIID riid, // IID[in] IUnknown *pUnkServer, // [out] IRpcStubBuffer **ppStub ); }// CLSID.

  • 3.5 ORPC ORPC,COM(channel), ORPC,IRpcChannelBuffer.typedef struct tagRPCOLEMESSAGE{ void *reserved1; unsigned long dataRepresentation; // endian/ebcdic void *Buffer; // ULONG cbBuffer; //ULONG iMethod; // void *reserved2[5]; ULONG rpcFlags; } RPCOLEMESSAGE; //ORPCclass IRpcChannelBuffer : public IUnknown //ORPC{ HRESULT GetBuffer(RPCOLEMESSAGE *pMessage, REFIID riid) = 0; //HRESULT SendReceive(RPCOLEMESSAGE pMessage,ULONG *pStatus) = 0; //ORPCHRESULT FreeBuffer(RPCOLEMESSAGE pMessage) = 0; //HRESULT GetDestCtx(DWORD *pdwDestCtx, void **ppvDestCtx) = 0;HRESULT IsConnected() = 0;};

  • 4 COMRPC

    /IDLIDLdictionary.idlMIDL.exeWin32SDKidlmidl dictionary.idl dictionary.h CC++dictionary_p.c CIDictionarydictionary_i.c CIDLGUIDdlldata.c C/(DllGetClassObject

  • DEFLIBRARYMyLibDESCRIPTION'IDictionary Interface Proxy/Stub DLL'EXPORTSDllGetClassObject@1 PRIVATEDllCanUnloadNow@2 PRIVATEGetProxyDllInfo @3 PRIVATEDllRegisterServer @4 PRIVATEDllUnregisterServer@5 PRIVATE win32 dll 5projectsettingsC/C++preprocessor definitionsREGISTER_PROXY_DLLprojectsettingsLinkobject/library modules uuid.lib rpcrt4.lib 4,5,6 MAKEREGISTER_PROXY_DLLrpcrt4.libuuid.lib(DLL,)

    IDLIDEMIDLIDLmakefile

  • 5. ,.:

    IMarshal,.

  • 5.1 IMarshalIMashal:class IMarshal : public IUnknown{ HRESULT GetUnmarshalClass( ...) = 0; //CLSID, CoMashalInterface.HRESULT GetMarshalSizeMax(...) = 0;// CoGetMarshalSizeMaxHRESULT MarshalInterface( ...) = 0; //, CoMarshalInterfaceHRESULT UnmarshalInterface(...) = 0;// CoUnmarshalInterfaceHRESULT DisconnectObject(...) = 0;// CoDisconnectObjectHRESULT ReleaseMarshalData(...) = 0;// CoReleaseMarshalData.};

  • ()IMarshalGetUnmarshalClassCLSID (IMarshalCOMCLSIDCLSID_StdMarshal, )GetMarshalSizeMaxMarshalInterface()streamproxyCLSIDCLSIDproxyproxyIMarshalIMarshal::UnmarshalInterfacestreamproxyproxy

  • IMarshalIMarshal

  • 5.2 CoGetClassObjectCOMcustom marshalingIClassFactory::CreateInstance, COM.

  • LPC/RPC

    CreateInstance