• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 42  文章 - 3  trackbacks - 0
            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            常用鏈接

            留言簿(2)

            隨筆檔案

            文章檔案

            網(wǎng)頁(yè)收藏

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            Recently, I have read Inside COM, it is not my first time to read it. But still I got some useful information from it.

            First of all, rather than inheriting, Containment and Aggregation are the two methods COM used to achieve reusability.
            Aggregation is the specialized form of Containment, in which the programmer doesn’t have to implement code in the outer component to forward/delegate a call to the inner component and hence makes the life of a programmer easier. In Aggregation, the outer component hands over the control of the interface, which is being implemented by the inner component, to the client directly and the outer component gets out of the picture. In Aggregation, the interface to the inner component is exposed directly to the client, which is in contrast with the Containment. The outer IUnknown and the Inner IUnknown will be having the different implementation of the QueryInterface and hence it violates the basic QueryInterface rules. To forward/delegate calls to the outer IUnknown, the inner component needs the outer component’s IUnknown interface pointer. The outer component passes its IUnknown interface pointer at the time of creating the inner component. The outer component calls CoCreateInstance and passes its IUnknown pointer in the second argument of CoCreateInstance. If this parameter is non-NULL, then the component is being aggregated, otherwise the component is not aggregated.

            Secondly, The IDispatch interface was initially designed to support Automation. It provides a late-binding mechanism to access and retrieve information about an object's methods and properties.In addition to the methods inherited from IUnknown, server developers must implement the following methods within the class definition of each object that is exposed:
            • GetTypeInfoCount returns the number of type descriptions for the object. For objects that support IDispatch, the type information count is always one.
            • GetTypeInfo retrieves a description of the object's programmable interface.
            • GetIDsOfNames maps the name of a method or property to a DISPID, which is later used to invoke the method or property.
            • Invoke calls one of the object's methods, or gets or sets one of its properties.

            When the client need to call the method provide by the server, and the code is like this:

             

             1HRESULT hret=CoInitialize(NULL); assert(SUCCEEDED(hret));
             2    CComPtr<IDispatch> ptr;
             3
             4    ptr.CoCreateInstance(L"InternetExplorer.Application");
             5      if(ptr==0{ wprintf(L"Unable to create Application\n"); return 1; }
             6    
             7    wchar_t *array=L"GoHome";
             9    long id;
            10    hret=ptr->GetIDsOfNames(IID_NULL,&array,1,LOCALE_SYSTEM_DEFAULT,&id);
            11    assert(SUCCEEDED(hret));
            12    
            13    DISPPARAMS noparams;  memset(&noparams,0,sizeof(noparams));
            14    
            15    hret=ptr->Invoke(id,IID_NULL,LOCALE_SYSTEM_DEFAULT,DISPATCH_METHOD,&noparams,NULL,NULL,NULL);   
            18    CoUninitialize();    return 0;
            19

            Third, Connection Points, Com’s Observer Pattern
            -Based on Callbacks
            -COM-Object can have one or more event sources
            -Per event source may be one or more subscribed event sink
            -asynchronous communication between a server and its clients

            //Client
            class myEventSink : public EventSink
            {
             void handleEvent(int arg)
             { cout << “myEventHandler” << arg << endl; }
            };

            //Server
            [ object, uuid(…) }
            interface IEventSource : IUnknown
            {
             HRESULT Attach( [in] IEventSink* PEveSink);
            };

            Protocol
            IConnectionPointContainer::FindConnectionPoint
            IConnectionPoint::Advise       //passing sink interface pointer, receiving cookie
            IConnectionPoint::Unadvice    //terminates notification

             

            posted on 2012-03-04 22:08 鷹擊長(zhǎng)空 閱讀(1238) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            国产欧美久久久精品影院| 久久精品这里热有精品| 久久精品国产欧美日韩| 亚洲中文字幕伊人久久无码| 亚洲AV无一区二区三区久久| 久久精品人人做人人爽97| 久久夜色tv网站| 久久影院午夜理论片无码| 亚洲国产精品久久久天堂| 一级做a爰片久久毛片16| 久久夜色精品国产亚洲| 久久久久中文字幕| 99久久免费国产精品特黄| 久久国产热精品波多野结衣AV| 精品久久久久久无码国产| 久久精品无码一区二区WWW| 国产精品激情综合久久| 亚洲中文字幕无码久久2020| 99久久婷婷国产综合精品草原| 亚洲人成伊人成综合网久久久| 国产精品免费久久久久影院| 无码国内精品久久人妻| 三级韩国一区久久二区综合| 久久精品国产精品国产精品污| 日韩精品久久久久久久电影蜜臀| 欧美午夜A∨大片久久| 国产精品久久久久影视不卡 | 久久本道伊人久久| 午夜福利91久久福利| 久久久久国产亚洲AV麻豆| A级毛片无码久久精品免费| 久久99精品久久久久久动态图 | 久久久久亚洲av毛片大| 久久91综合国产91久久精品| 人妻精品久久无码专区精东影业| 无码国内精品久久综合88| 一级女性全黄久久生活片免费 | 999久久久免费精品国产| 人妻无码αv中文字幕久久琪琪布| 国产欧美久久久精品影院| 久久亚洲AV无码精品色午夜麻豆|