Microsoft Developer Network > 포럼 홈 > 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일 월요일 오후 5: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일 월요일 오후 6: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일 월요일 오후 6: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일 월요일 오후 7: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.