Wednesday, December 16, 2015

Limiting COM ourproc server instances

A common approach to limit an application to single instance is to create a named kernel objects (mutex,semaphore etc) from main(). This is not always best method and may lead to freeze the client application in case of an outproc server. A typical case is the activation of outproc server from different users or users with different privileges.

An elementary feature of COM server is to launch the server during very first CoCreateInstance() call and  connect the subsequent calls to existing server. If  client calls are from different privileges(For example standard and administrator), it will try to launch multiple server instances and it is a security measure. So the second and subsequent calls will get blocked for 120 seconds and leads to application freeze. It will return failure after 120 seconds.

To limit COM server instance to one, there is another method which can be accomplished by modifying COM identity(.rgs file). By default all COM servers are with Launching User identity unless specified explicitly. This can be changed to This User with the user credentials which is advisable to retain security. Another option is The Interactive user. But it will create multiple instances if client is not in an interactive user session(For example call from Windows Service).

Wednesday, August 12, 2015

Missing ON_WM_MEASUREITEM_REFLECT

Last week i have come across a strange issue in customized CListCtrl. A dialog is having two ListCtrls of them. The row height changes are not getting reflected to the second control while changing font size. 

Why is it happening for the second control or  is it happening only for the second object?
I swapped it for confirmation. Surprisingly the result was same. So the issue is not with the object, it could be with the Tab order. But the control does not have any tab order specific implementation.

To uncover this bizarre, i had gone through MFC source code implementation of CWnd::OnMeasureItem() since it is responsible for row height and width manipulation. As per the implementation of this method, it iterates all the ListCtrls in a dialog using CWnd::GetDescendantWindow() and invokes virtual method CWnd::MeasureItem()CWnd::GetDescendantWindow() method uses control ID to uniquely identify each control. In our scenario, the control ID was same for both ListCtrls and it only invokes  CWnd::MeasureItem() for the first control.

It can happen for other handlers too. So be conscientious while setting the control ID.




Keep an eye on your Native API prototype for interop calls

Few weeks back, we have observed "an unexpected process termination" crash in a WPF app. From the crash dump, provides below calls...