COM Category ComboBox

Environment:VC++ 6.0 SP5, NT 4.0, Win95/98, W2K

Introduction

I like the idea of programming by components. After reading on the topic of COM Categories I started to think about a possible way to make kind of plugins for my applications. The first idea came at home when I was thinking about my job. We do fingerprint identification and use multiple hardware to capture a fingerprint picture. So I generalized fingerprint scanners as hardware pieces that delivers fingerprint pictures. Then I built an interface that is generic to all scanners. This allow us now to choose the scanner we would like to use at run time.

You may get more information in the articles from Len Holgate:
Writing extensible applications, Component Category Manager wrapper classes.

ComboBox

The ComboBox is built according to an CATID (UUID) representing the COM Category. It searches the registry all COM objects implementing that Category using ICatInformation. Then it add them in the list box of the ComboBox. It also sets the 32-bit value associated with the specified item in the combo box to be a CString's pointer containing the interface identifier (IID). This will permit to create the COM object according to user choice at runtime. To optimize the speed of displaying, the ComboBox search the registry only if a user click on the dropdown. It also cache in the registry the latest value selected for creation speed.

Usage

To use this WTL control, place a ComboBox control on your dialog. Add a member variable to your dialog implementation file:
    CCOMCategoriesComboBox m_catCombo;

In the OnInitDialog() event handler, add the following line:

  LRESULT OnInitDialog(UINT /*uMsg*/, 
                       WPARAM *wParam*/,
                       LPARAM *lParam*/,
                       BOOL& /*bHandled*/)
  {
    ...
    
    // Attach controls to members
     
    m_catCombo.SubclassWindow( GetDlgItem(IDC_COMBO_CAT) );

    ...
  }

Add the following reflection macro to your main message map:

   BEGIN_MSG_MAP(CMainDlg)
      ...
      REFLECT_NOTIFICATIONS()
  END_MSG_MAP()

Use this to initialize the CCOMCategoriesComboBox in the dialog constructor:

CMainDlg() : 
  m_catCombo( "{00021493-0000-0000-C000-000000000046}", 
                     // Internet Explorer Browser Band CATID
              CString(_T("SOFTWARE\\Tech Head\\COMCategoryComboBox")),
              CString(_T("IE Browser Band")) )
{
}

To get user's selected COM object, you have two solutions:

  • Read the value written in the registry at HKLM\SOFTWARE\Tech Head\COMCategoryComboBox\IE Browser BandIID
  • Use CComboBox::GetItemDataPtr to retrieves the application-supplied 32-bit value associated with the specified combo box item that is a pointer to a CString containing the interface identifier (IID).

Faced Problems

None (at the moment).

About Laurent Kempi

I am originally from Mulhouse, east of France, and currently searching for a new job. In 1995, I was graduated Software Engineer in ESSAIM Higher School of Engineering. I develop mainly in C++ for Windows platforms and I have a strong knowledge of the Windows security/logging system. I am currently digging in XML, SOAP and actively learning C# and .Net platform. I have knowledge in Object Oriented Design, UML, Design Patterns and be familiar with COM/COM+, DCOM, ATL/WTL, STL, MFC.

Click here to visit Tech Head, Laurent Kempi's homepage.

Downloads



Comments

  • Compiling error: No 'atlres.h' file

    Posted by Legacy on 01/20/2004 12:00am

    Originally posted by: dan zhao

    Where is the atlres.h file

    Reply
  • Excellent Article

    Posted by Legacy on 07/10/2002 12:00am

    Originally posted by: Monika

    Thanks. I was attempting something similiar and this article was a huge help. The only major difference I added was to use interface inheritance to allow for polymorphism, but I like your approach too.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Today's "average" business in general is ever more reliant on technology and the Internet. Mobility is the most often cited business trend that has transformed the way many of us work and communicate. From an IT security perspective, this means that protection methods and tools from even a few years ago are rapidly becoming "unfit for purpose." This guide provides crucial facts to assist you in building a robust business case, meeting the demands of your business, and protecting against threats now and in the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds