Why does an RCW handle WM_PAINT when calling it from its own apartment

45 Views Asked by At

My application is native windows application (MFC/Win32) which loads .NET plugins via COM. The application exposes its document model via COM (implemented in ATL).

I have a line of code which looks like this on the .NET side:

var settings = Application.UserSettings;

With a breakpoint in my WM_PAINT handler in the native application, the breakpoint will trigger on this line (amongst others). I'm not able to see the stack trace past this point but I assume it stopped execution in the WM_PAINT handler, since it contains my only breakpoint, but I'm not able to see the stack past the RCW.

I suspect that in the get_UserSettings property getter, the RCW will handle WM_PAINT. I disabled the WM_PAINT dispatching as described this article and the WM_PAINT dispatching stopped, which goes a long way towards confirming my suspicion.

This all happens on the UI thread which is STA. The COM object is STA and was created on the UI thread. I thought COM/RCW would only handle WM_PAINT when doing cross-apartment marshaling, while it waits for the method call to finish executing.

My question is: Why does the RCW handle WM_Paint in this case?

0

There are 0 best solutions below