wishfly的专栏

-- 只要路是对的,就不怕路远

用户操作
[即时聊天] [发私信] [加为好友]
wishfly ID:wishfly
254329次访问,排名241好友0人,关注者4
wishfly的文章
原创 142 篇
翻译 0 篇
转载 781 篇
评论 64 篇
wishfly的公告
只为文摘,不为传播。 版权就不一一声明了。 在此一并感谢原文作者。
最近评论
sap99:www.sap99.com/,SAP99资料多多

SAP免费资料下载
http://www.sap99.com

有很多的学习资料,推荐一下,
eastsun:我是这篇“产品经理的14条军规”的原创作者chanjiajun(eastsun),请作者删除本篇复制品。
eastsun:我是这篇“产品经理的14条军规”的原创作者chanjiajun(eastsun),请作者删除本篇复制品。
eastseek:你这是原创吗?
sap99:http://www.sap99.com/
,SAP免费资料下载
SAP99资料多多

http://www.sap99.com

有很多的学习资料,推荐一下,
文章分类
收藏
    相册
    geren
    blog
    anytao(.Net)
    caimouse
    Forefront Edge Security
    houdy
    jdon
    junguo的专栏
    optman的专栏
    ouyang2008的专栏
    shrekmu
    周公的专栏
    奋斗,我一生的主题
    寒星轩
    思归呓语
    智慧的鱼(DirextX)
    李先静
    热力西雅图
    第二人生的源码分析
    胡长城
    蝈蝈俊.net
    许式伟的专栏
    阿波的专栏
    陆其明's Blog
    黄国强
    工具
    技术
    ben point
    chinaunix
    Chris Gould's Linux Kernel Architecture
    Chrome sourcecode
    directshow
    directshow.cn
    Eric
    Forefront TMG (ISA Server) Product Team Blog
    google
    ibm - linux
    joel on software
    joyfire.net
    kernel.org
    linuxforum
    lucene
    OpenSolaris User Group
    SQL WHERE Clause
    中国协议分析网
    利索脚
    海迪
    其他
    存档
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载 CoMarshalInterThreadInterfaceInStream使用收藏

    新一篇: 深入Linux网络核心堆栈  | 旧一篇: 我有罪...

     
    You have to marshal the IServiceProvider interface from your main thread to your background thread.
     
    In your SetSite call (which is guaranteed to be called on the main UI thread), marshal the IServiceProvider interface into a shared stream (IStream) object using CoMarshalInterThreadInterfaceInStream. You’ll need to make sure that this shared object can be accessed from both threads. In your background thread, when you need to get at the IServiceProvider, call CoGetInterfaceAndReleaseStream to get back a proxied IServiceProvider that works for the calling thread. Note that you can call this only once, so cache the interface that you get back. You can then call through this interface to QueryService. See the example code below:
     
    class CMyPackage : public IVsPacakge
    {
    private:
     CComPtr< IStream > m_pSPStream; // Used to marshal IServiceProvider between threads
     CComPtr< IServiceProvider > m_pBackgroundSP; // IServiceProvider proxy for the background thread
     
    public:
     HRESULT SetSite( IServiceProvider* pSP )
     {
        // Marshal the service provider into a stream so that
        // the background thread can retrieve it later
        CoMarshalInterThreadInterfaceInStream(IID_IServiceProvider, pSP, &m_pSPStream);
     
        //... do the rest of your initialization
     }
     
     // Call this when your background thread needs to call QueryService
     // The first time through, it unmarshals the interface stored
     HRESULT QueryServiceFromBackgroundThread(
        REFGUID rsid,     // [in] Service ID
        REFIID riid,      // [in] Interface ID
        void **ppvObj     // [out] Interface pointer of requested service (NULL on error)
     {
        if( !m_pBackgroundSP )
        {
          if( !m_pSPStream )
          {
            return E_UNEXPECTED;
          }
     
          HRESULT hr = CoGetInterfaceAndReleaseStream( m_pSPStream, IID_IServiceProvider, (void **)&m_pBackgroundSP );
          if( FAILED(hr) )
          {
            return hr;
          }
     
          // The CoGetInterfaceAndReleaseStream has already destroyed the stream.
          // To avoid double-freeing, the smart wrapper needs to be detached.
          m_pSPStream.Detach();
        }
     
        return m_pBackgroundSP->QueryService( rsid, riid, ppvObj );
     }
    };

    发表于 @ 2008年06月27日 11:30:00|评论(loading...)|编辑|收藏

    新一篇: 深入Linux网络核心堆栈  | 旧一篇: 我有罪...

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © wishfly