Functions


CoRegisterMessageFilter Function

Registers with OLE the instance of an IMessageFilter interface, which is to be used for handling concurrency issues on the current thread. Only one message filter can be registered for each thread. Threads in multi-threaded apartments cannot have message filters.

Syntax

C++
HRESULT CoRegisterMessageFilter(
  __in_opt   LPMESSAGEFILTER lpMessageFilter,
  __out_opt  LPMESSAGEFILTER *lplpMessageFilter
);

Parameters

lpMessageFilter [in, optional]

A pointer to the IMessageFilter interface on the message filter. This message filter should be registered on the current thread, replacing the previous message filter (if any). This parameter can be NULL, indicating that no message filter should be registered on the current thread.

Note that this function calls AddRef on the interface pointer to the message filter.

lplpMessageFilter [out, optional]

Address of the IMessageFilter* pointer variable that receives the interface pointer to the previously registered message filter. If there was no previously registered message filter for the current thread, the value of *lplpMessageFilter is NULL.

Return Value

If the instance was registered or revoked successfully, the return value is S_OK; otherwise, it is S_FALSE.

Remarks

To revoke the registered message filter, pass the previous message filter (possibly NULL) as the lpMessageFilter parameter to CoRegisterMessageFilter.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderObjbase.h
LibraryOle32.lib
DLLOle32.dll

See Also

IMessageFilter

Send comments about this topic to Microsoft

Build date: 11/12/2009

Tags :


Community Content

Paul Harrington
Behavior if current IMessageFilter is NULL?
The default behavior for the default message filter (NULL) is:

HandleInComingCall:
return SERVERCALL_ISHANDLED;

RetryRejectedCall:
return (DWORD)-1;

MessagePending:
return PENDINGMSG_WAITDEFPROCESS;

Tags : contentbug

dmex
vb.net syntax
<DllImport("ole32.dll", ExactSpelling:=True)> _
Public Shared Function CoRegisterMessageFilter(ByVal newFilter As IntPtr, ByRef oldMsgFilter As IntPtr) As Integer End Function
Tags : vb.net

dmex
C# syntax
[DllImport("ole32.dll", ExactSpelling=true)]
public static extern int CoRegisterMessageFilter(IntPtr newFilter, ref IntPtr oldMsgFilter);
Tags : c#

Paul Harrington
Only STA (APARTMENT_THREADED) threads may have message filters

If CoRegisterMessageFilter is called on a thread which was initialized with COINIT_MULTITHREADED, then the return code is CO_E_NOT_SUPPORTED (0x80004021)

Tags :

Page view tracker