Microsoft Developer Network > Página principal de foros > Visual Studio Tools for Office > CoRegisterMessageFilter doesn't appear to be registering the message filter.
Formular una preguntaFormular una pregunta
 

RespondidaCoRegisterMessageFilter doesn't appear to be registering the message filter.

  • lunes, 27 de octubre de 2008 17:34ejm78 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.

Respuestas

  • lunes, 27 de octubre de 2008 18:32Geoff Darst - MSFTUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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

Todas las respuestas

  • lunes, 27 de octubre de 2008 18:32Geoff Darst - MSFTUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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
  • lunes, 27 de octubre de 2008 19:33ejm78 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.