Configuration | Basics blocking so that you can respond and handle the situation. For example, when accessing TwinCAT XAE via COM, the Visual Studio instance will reject further COM calls while still executing a previous COM call. As a result, the client application will issue an RPC_E_CALL_REJECTED error and, without further intervention, will not repeat the call. By writing a user-defined message filter, the programmer has the ability to retry the COM call when the client application receives notification of a denied COM call from the COM server.
The following screenshot shows a typical error output by the Visual Studio COM server when an instance is still busy executing a previous COM call. To avoid this situation and implement a message filter that responds to this rejected COM call, the application engineer must implement the IMessageFilter interface. This interface consists of three methods: HandleIncomingCall(): Provides a single entry point for incoming calls MessagePending(): Indicates that a message has been received while COM is waiting for a remote call to be answered. RetryRejectedCall(): Provides the ability to respond to a rejected COM call.
Note that message filters can only be applied to STA threads and that only one filter can be applied to each thread. Multithreaded apartments, e.g. console applications, cannot have message filters. These applications must run in an STA thread to apply message filtering. See the appendix of this documentation for more information on COM threading. The following code snippet shows a sample of how the IMessageFilter interface can be used in C#. Note that this code is also used in many samples in our Samples section, and is also available as a separate sample download.
[ComImport(), Guid("00000016-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] interface IOleMessageFilter { [PreserveSig] int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo); [PreserveSig] int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType); [PreserveSig] int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType); } The following class implements this interface and adds two more methods: Register() and Revoke(). public class MessageFilter :
IOleMessageFilter { public static void Register() { IOleMessageFilter newFilter = new MessageFilter(); IOleMessageFilter oldFilter = null; int test = CoRegisterMessageFilter(newFilter, out oldFilter); if (test != 0) TE1000 29 Version: 1.7.0