, , . , . , . , , 1. , , . a (method remoting) , .
ORPC (Object Remote Procedure Call - ). ORPC MS-RPC ( Microsoft), DCE (Distributed Computing Environment - ). MS-RPC , ( DLL) ( Security Support Provider DLL). . - UDP (User Datagram Protocol - ), 2. , .
, (marshaling), o , . , . (marshaled state) . , , , , (serialized) . , .
. , . , . , , , , . . API- CoMarshalInterface, .
CoMarshalInterface . , API- CoUnmarshalInterface , , , CoUnmarshalInterface. CoMarshalInterface , . :
typedef enum tagMSHCTX { MSHCTX_INPROC = 4, // in-process/same host // / MSHCTX_LOCAL = 0, // out-of-process/same host // / MSHCTX_NOSHAREDMEM = 1, // 16/32 bit/same host // 16/32- / MSHCTX_DIFFERENTMACHINE = 2 // off-host // } MSHCTX;
, , MSHCTX. CoMarshalInterface :
typedef enum tagMSHLFLAGS { MSHLFLAGS_NORMAL, // marshal once, unmarshal once // , MSHLFLAGS_TABLESTRONG, // marshal , unmarshal many // . MSHLFLAGS_TABLEWEAK, // marshal once, unmarshal many // , MSHLFLAGS_NOPING = 4, // suppress dist. garbage collection // } MSHLFLAGS;
(normal) , (call marshaling), , , , CoMarshalInterface. (table) , CoMarshalInterface. .
, CoMarshalInterface IStream, . IStream - Read Write. CoMarshalInterface Write IStream, , . IStream (raw) , API- CreateStreamOnHGlobal:
HRESULT CreateStreamOnHGlobal( [in] HGLOBAL hglobal, // pass null to autoalloc // [in] BOOL bFreeMemoryOnRelease, [out] IStream **ppStm);
IStream :
void UseRawMemoryToPrintString(void) { void *pv = 0; // alloc memory // pv = malloc(13); if (pv != 0) { // write a string to the underlying memory // memcpy(pv, "Hello, World", 13); printf((const char*)pv); // free all resources // free (pv); } }
, IStream memcpy:
void UseStreamToPrintString(void) { IStream *pStm = 0; // alloc memory and wrap behind an IStream interface // IStream HRESULT hr = CreateStreamOnHGlobal(0, TRUE, &pStm); if (SUCCEEDED(hr)) { // write a string to the underlying memory // hr = pStm->Write("Hello. World", 13, 0); assert (SUCCEEDED (hr)); // suck out the memory // HGLOBAL hglobal = 0; hr == GetHglobalFromStream(pStm, &hglobal); assert(SUCCEEDED(hr)); printf((const char*)GlobalLock(hglobal)); // free all resources // GlobalUnlock(hglobal); pStm->Release(); } }
API- GetHGlobalFromStream (handle) , CreateStreamOnHGlobal. HGLOBAL .
API- CoMarshalInterface :
HRESULT CoMarshalInterface( [in] IStream *pStm, // where to write marshaled state // [in] REFIID riid, // type of ptr being marshaled // [in, iid_is(riid)] IUnknown *pItf, // pointer being marshaled // [in] DWORD dwDestCtx, // MSHCTX for destination apt. // MSHCTX [in] void *pvDestCtx, // reserved, must be zero // , [in] DWORD dwMshlFlags // normal, vs. table marshal // );
, :
HRESULT WritePtr(IRacer *pRacer, HGLOBAL& rhglobal) { IStream *pStm = 0; hglobal = 0; // alloc and wrap block of memory // HRESULT hr = CreateStreamOnHGlobal(0, FALSE, &pStm); if (SUCCEEDED(hr)) { // write marshaled object reference to memory // hr = CoMarshalInterface(pStm, IID_Iracer, pRacer, MSHCTX_DIFFERENTMACHINE, 0, MSHLFLAGS_NORMAL); // extract handle to underlying memory // if (SUCCEEDED(hr)) hr = GetHGlobalFromStream(pStm, &rhglobal); pStm->Release(); } return hr; }
5.1 , . CoMarshalInterface . MSHCTX_DIFFERENTMACHINE, - .
, , , API- CoUnmarshalInterface:
HRESULT CoUnmarshalInterface( [in] IStream *pStm, // where to read marshaled state // [in] REFIID riid, // type of ptr being unma shaled // [out, iid_is(riid)] void **ppv // where to put unmarshaled ptr // );
CoUnmarshalInterface , . , , . - CoUnmarshalInterface , , . :
HRESULT ReadPtr(HGLOBAL hglobal, IRacer * &rpRacer) { IStream *pStm = 0; rpRacer = 0; // wrap block of existing memory passed on input // , // HRESULT hr = CreateStreamOnHGlobal(hglobal, FALSE, &pStm); if (SUCCEEDED(hr)) { // get a pointer to the object that is legal in this apt. // , hr = CoUnmarshalInterface(pStm, IID_Iracer, (void**)&rpRacer); pStm->Release(); } return hr; }
.
Windows NT 4.0 . , , 1996 . . 5.2 . "MEOW" ( )3, ( , (standard), (custom)), IID , . , .
" " (garbage collection) AddRef/Release, . (tuple) OXID/OID/IPID, . (Object Exporter Identifier OXID). OXID IPC- . (Object Identifier OID) CoUnmarshalInterface . (Interface Pointer Identifier - IPID) . IPID ORPC .
OXID , , - I . OXID IPC - , , OXID (OXID Resolver - OR). Windows NT 4.0 OR RPCSS. , OXID OR. , OR . , OR IPC- . CoUnmarshalInterface , OXID I OR. , , OR OXID OXID- IPC- . , , OR , OXID , , OXID . OXID , OR - , RPC. , - , , OR , .
OXID, OR - OXID ( 135 TCP UDP) . OXID , OXID. , . , OR - , I , . , OR OXID. OR , , . , . , (OXID), , . , ( TCP), . , - , .
1 , , .
2 UDP TCP (Transmission Control Protocol) - - - , TCP. , DCE RPC, , RPC. , UDP . , UDP, RPC / . .
3 Microsoft (Microsoft Program Manager), , , MEOW Microsoft Extended Object Wire ( Microsoft). , , .