windows編程潘愛民com講座_第1頁(yè)
windows編程潘愛民com講座_第2頁(yè)
windows編程潘愛民com講座_第3頁(yè)
windows編程潘愛民com講座_第4頁(yè)
windows編程潘愛民com講座_第5頁(yè)
已閱讀5頁(yè),還剩9頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

COMCOMDllGetClassObjectDllGetClassObject數(shù)調(diào)用DllGetClassObject引出–classCNewClass:publicCOldClass包容聚合對(duì)象對(duì)象對(duì)象classclassCB:publicISomeInterface,public{ CB(~CB();HRESULTstdcallQueryInterface(constIID&iid,void**ppv);ULONGstdcallAddRef();ULONGstdcall//ISomeInterfacemembersHRESULTstdcallSomeFunction();//IOtherInterfacemembersHRESULTstdcallOtherFunction();privateISomeInterfaceCB::CB({m_Ref=0;}CB::~CB({if(m_pSomeInterface!=NULL)}HRESULT{HRESULTresult=::CoCreateInstance(CLSID_ComponentA,NULL,CLSCTX_INPROC_SERVER,IID_ISomeInterface,(void**)&m_pSomeInterface);if(FAILED(result)) returnS_OK;}constIID&iid,void{CB HRESULT if(pUnknownOuter!=NULL)returnCLASS_E_NOAGGREGATION;pObj=newCB();if(pObj==NULL)returnif(FAILED(hr))deletepObj;}//Obtainthefirstinterfacepointer(whichdoesanAddRef)hr=pObj->QueryInterface(iid,ppv);return}HRESULTstdcallCB::SomeFunction({returnm_pSomeInterface->SomeFunction(}HRESULTstdcallCB::OtherFunction({}HRESULTHRESULTstdcallCB::SomeFunction({if(...{HRESULTresult=m_pSomeInterface->SomeFunction(return}{}}intFunc1(intx,inty){returnx*y;}intFunc2(intx,inty){returnint(*MyFunc)(int, MyFunc= inta=MyFunc(10, MyFunc=intb=MyFunc(10,classvirtualvoidstdcallMethod1(int,int)=0;virtualvoidstdcallMethod2(int)=0;classvirtualvoidstdcallOperator1(int,int)=0;virtualvoidstdcallOperator2(int)=0;classCMyObject:public指針類型并不實(shí)例化CMyObjectVtable1*p1=代碼片斷p1->Method1(a,代碼片斷Vtable2*p2=(Vtable2*)p1;p2->Operator1(a,b);對(duì)象外外義classCB:public{CB(~CBHRESULTstdcallQueryInterface(constIID&iid,void**ppv);ULONGstdcallAddRef();ULONGstdcall//IOtherInterfacemembersHRESULTstdcallOtherFunction();HRESULTprivateIUnknown*m_pUnknownInner;//pointertoA's{if(iid==IID_IUnknown)*ppv=(IUnknown*)this;((IUnknown*)(*ppv))->AddRef()}elseif(iid==IID_OtherInterface)*ppv=(IOtherInterface*)this;}elseif(iid==IID_SomeInterface)returnm_pUnknownInner->QueryInterface(iid,ppv)}else*ppv=}return}2.委托IUnknown(1)當(dāng)對(duì)象被聚合時(shí),調(diào)用外部對(duì)象的IUnknown(2)當(dāng)對(duì)象未被聚合時(shí),調(diào)用非委托IUnknown接IOtherInteISomeInteface 為controllingunknown內(nèi)部對(duì)象類廠的e必須檢查r參數(shù),如果非L,則表明聚合,內(nèi)部對(duì)象把指針保存起來,但不調(diào)用f。若內(nèi)部對(duì)象不支持聚N如果pUnkOuter參數(shù)非NULL,并且外部對(duì)象請(qǐng)求對(duì)于除了非委托版本的Inknon之外的接口,它的三個(gè)Inknn調(diào)用必須全部委托給外部對(duì)象的pnkOtHRESULTCoCreateInstance(constCLSID&IUnknownconstIID&iid,(voidHRESULTconstIID&iid,voidclassCA:publicclassCA:publicISomeInterface,public{內(nèi)義CA(IUnknown~CA(publicvirtualHRESULTstdcallQueryInterface(constIID&iid,void**ppv);virtualULONGstdcallAddRef();virtualULONGstdcallRelease()virtualHRESULTstdcallconstIID&iid,void**ppv);virtualULONG stdcallNondelegationAddRef();virtual stdcallNondelegationRelease()privateIUnknown*m_pUnknownOuter;//pointertoouterclass{virtualHRESULTstdcallconstIID&iid,void**ppv)=0;virtualULONGstdcallNondelegationAddRef()=0;virtualULONGstdcallNondelegationRelease()=0;HRESULTCA::NondelegationQueryInterface(constIID&iid,void{if(iid==IID_IUnknown)*ppv=(INondelegatingUnknown*)this;((IUnknown*)(*ppv))->AddRef();}elseif(iid==IID_SomeInterface)*ppv=(ISomeInterface*)this;((ISomeInterface*)(*ppv))->AddRef();}else*ppv=returnE_NOINTERFACE}return}ULONGCA::AddRef{if(m_pUnknownOuter!=NULLreturn}ULONGCA::Release{}HRESULTCA::QueryInterface(constIID&iid,void{if(m_pUnknownOuter!=NULL}廠的CreateInstance函數(shù)與包容模型相同。但{HRESULTresult=::CoCreateInstance(CLSID_ComponentA,pUnknownOuter,CLSCTX_INPROC_SERVER,if}CB::~CB({if(m_pUnknownInner!=NULL)m_pUnknownInner->Release();}CA::CA(IUnknown{CA::CA(IUnknown{m_pUnknownOuter=}constIID&iid,void{內(nèi)//iidmustbeIID_IUnknownforif((pUnknownOuter!=NULL)&&(iid!=IID_IUnknown)部return對(duì)象//CreatetheobjectpassingfunctiontonotifyonCA*pObj=newCA創(chuàng)的if(pObj==NULL)return創(chuàng)建//Obtainthefirstinterfacepointer(whichdoesanAddRef)HRESULThr=pObj->NondelegatingQueryInterface(iid,ppv);returnhr;建}HRESULT{IUnknown*pUnknownOuter=(IUnknownHRESULTresult=::CoCreateInstance(CLSID_CompA,pUnknownOuter,IID_IUnknown,(void**)&m_pUnknownInner);if(FAILED(result))returnE_FAIL;result=m_pUnknownInner->QueryInterface(IID_ISomeInterface,(void**)&m_pSomeInterface);if{}returnS_OK;}constIID&iid,void{CB*pObj;HRESULThr;if(NULL!=pUnknownOuter)returnpObj=newCB();returnpObj->AddRef();//TheReferencecountofpObjis1hr=pObj->Init();if(FAILED(hr)) g_CompBNumber--;deletereturnE_FAIL;}hr=pObj->QueryInterface(iid,ppv); //TheReferencecountofpObjis1returnhr;}CB::~CB({m_Ref=IUnknown*pUnknownOuter=this;pUnknownOuter->AddRef();if(m_pSomeInterface!=NULL)if(m_pUnknownInner!=NULL)}(客戶進(jìn)程(組件進(jìn)程(1)自定義列集法(custommarshaling)或基本列集法(basicmarshalingarchitecture)(2)標(biāo)準(zhǔn)列集法(standard列集:找到代理對(duì)象的CLSD象;列集數(shù)據(jù)包,包括跨進(jìn)程信息。這些信息被稱為對(duì)象引用(saedobtfeene)散集:客戶進(jìn)程中,根據(jù)傳輸過來的CLSD代理對(duì)象,并且把列集數(shù)據(jù)包傳給代理對(duì)象。代理對(duì)象向客戶返回一個(gè)接口指針。HRESULTCoMarshalInterface(IStream*pStm,REFIIDriid,IUnknown*pUnk,void*dwDestContext,unsignedlongpvDestContext,unsignedlongmshlflagsHRESULTCoUnmarshalInterface(IStreamREFIIDriid省代理對(duì)象,其CLSID為CLSID_StdMarshal)。classIMarshal:public{HRESULTGetUnmarshalClass(...)=0;HRESULTGetMarshalSizeMax(...)=0;HRESULTMarshalInterface(...)=0;HRESULTUnmarshalInterface(...)=0;HRESULTDisconnectObject(...)=0;HRESULTReleaseMarshalData(...)=0;調(diào)用IMarshal::UnmarshalInterface,把stream中的數(shù)據(jù)傳給proxy,proxy根據(jù)而這個(gè)對(duì)象使用custom① ③調(diào)用類廠對(duì)對(duì)象不需要實(shí)現(xiàn)Irshal,COM提供代理對(duì)象,其CLI為CLI_tdarhal跨進(jìn)程通信被抽象成RC通道,RC通道也是一個(gè)COM對(duì)象COMORPC建立在MSRPC基礎(chǔ)上MSRPC{HRESULTGetBuffer(RPCOLEMESSAGEREFIIDriid)=HRESULTSendReceive(RPCOLEMESSAGEULONG*pStatus)=0;HRESULTFreeBuffer(RPCOLEMESSAGEpMessage)=0;HRESULTGetDestCtx(DWORD*pdwDestCtx,HRESULTIsConnected()=0;{HRESULTConnect(IRpcChannelBuffer*pRpcChannelBuffer)=0; Disconnect()=0;{ Connect(IUnknown*pUnkServer)=0; Disconnect()=0; Invoke(RPCOLEMESSAGEIRpcChannelBuffer*pChannel)=0;IRPCStubBuffer*IsIIDSupported(REFIIDiid)=0; CountRefs()=0; DebugServerQueryInterface(void**ppv)=0; DebugServerRelease(void*pv)=0;存根管理器通過Cnt方法把接口存根與目標(biāo)對(duì)象聯(lián)系起來clsid=LookUpInRegistry(iid);CoGetClassObject(clsid,clsid=LookUpInRegistry(iid);CoGetClassObject(clsid,CLSCTX_SERVER,NULL,IID_IPSFactoryBuffer,&pPSFactory));pPSFactory->CreateProxy(pUnkOuter,riid,&pProxy,clsid=LookUpInRegistry(iid);CoGetClassObject(clsid,CLSCTX_SERVER,NULL,IID_IPSFactoryBuffer,&pPSFactory));pPSFactory->CreateStub(iid,pUnkServer,如果是接口指針,調(diào)用如果是接口指針,則調(diào)用調(diào)用返回:對(duì)象-〉客戶,處理[t]、nout參數(shù)及返回值在CGtCassObt函數(shù)內(nèi)部,它找到EE組件的程序位置后,啟動(dòng)組件進(jìn)程,等待...組件進(jìn)程啟動(dòng)后,調(diào)用CoIntialze初始化,創(chuàng)建所有的類廠,調(diào)用CRegieCassObt把類廠注

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論