Microsoft 开发人员网络 > 论坛主页 > Visual Studio Tools for Office > CoRegisterMessageFilter doesn't appear to be registering the message filter.
提出问题提出问题
 

已答复CoRegisterMessageFilter doesn't appear to be registering the message filter.

  • 2008年10月27日 17:34ejm78 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    I am trying to implement a custom COM message filter using the code referenced here (http://msdn.microsoft.com/en-us/library/ms228772(VS.80).aspx).  However, the CoRegisterMessageFilter call in MessageFilter.Register returns a result of -2147467231.  According to the documentation, the only valid return results are 0 and 1 for S_OK and S_FALSE.  If I let the code run, I am still getting the RPC server is busy error, but the retry code is never called.  This leads me to believe that the message filter is not getting registered.  Does anybody have any idea what this return result means?

    - IDE: Visual Studio 2008
    - Framework: .Net 3.5 SP1
    - Language: VB.net
    - I'm not actually using VSTO, but instead accessing office throught the PIA's.
    - I am calling register before instantiating a PowerPoint.Application object and revoking it when I am done.

    I am not sure what other information will be needed.  I didn't post any code because I used an exact copy of what is in the document I referenced above.  If you need any other info, please just ask.

    Thanks in advance for all your time!
    Eric.

答案

  • 2008年10月27日 18:32Geoff Darst - MSFT答复者用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    Hi,

    You are getting a CO_E_NOT_SUPPORTED error.  Most likely that means you are calling CoRegisterMessageFilter from a thread that is in the Multi-Threaded-Apartment (MTA).  MessageFilters are only supported on Single-Threaded-Apartment (STA) threads.

    Sincerely,

    Geoff Darst
    Microsoft VSTO Team

全部回复

  • 2008年10月27日 18:32Geoff Darst - MSFT答复者用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    Hi,

    You are getting a CO_E_NOT_SUPPORTED error.  Most likely that means you are calling CoRegisterMessageFilter from a thread that is in the Multi-Threaded-Apartment (MTA).  MessageFilters are only supported on Single-Threaded-Apartment (STA) threads.

    Sincerely,

    Geoff Darst
    Microsoft VSTO Team
  • 2008年10月27日 19:33ejm78 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Geoff - Thank you for the quick reply!  You are absolutely correct.  Although I knew that it had to be running on an STA thread, I didn't realize that my NUnit tests (yes, I am planning on migrating to MS Test) were running in MTA!

    I added a check when registering the MessageFilter that throws an exception if the current thread is not STA.  This is helpful because it will block it right from the start, rather than allowing to code to execute while not using the custom MessageFilter.  Just thought I would add that for anyone else running into a similar problem.

    Thank you so much for your help!

    Eric.