Linking with Xerces 2.8.0 statically

February 12, 2008 at 10:33 PMAmer Gerzic

Couple of weeks ago, I needed to parse a set of XML files. As always, my first thought was to search the web for free XML parsers. But then I remembered that I found a solution in the past: Xerces XML parser. Even though, xerces was originally written in Java, there is an excellent port to c/c++. Xerces was developed by Apachi Software Foundation, and it supports wide range of compilers. To use it with Visual Studio 2005 C++ compiler, following steps are required:

  1. Download compiler in binary form from here;
  2. Unpack into any folder; This step will create subfolders include and lib;
  3. Add path include and lib folders to VC++ directories;
  4. To statically link to a project, link with xerces-c_static_2.lib or (xerces-c_static_2D.lib for debug version);
  5. Set to ignore libcmt.lib

Steps 4 and 5 are shown in the screen shot below:

 

Posted in: CPP

Tags: , , , , , ,

How to disable context sensitive help in MFC?

May 31, 2007 at 5:05 PMAmer Gerzic

Couple of days ago, I worked on an MFC application that required special functionallity of F1 key. At first, I thought that all I need is to override application's PreTranslateMessage function and trap the F1 key. However, I was wrong. Every time I pressed F1 key, the application performed custom function, but also popped message box saying that help file could not be located. My first thought was that MFC/Windows is placing a windows hook to trap such functionality and that the workaround might not be very elegant. Fortunatly that was not the case. After some investigation, I noticed the following code:

BEGIN_MESSAGE_MAP(CDRSApp, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()

In other words, main application is getting notification to handle help request and is passing it to default MFC implementation. Once the ON_COMMAND line is commented out, such hadling is disabled.

Posted in: CPP | MFC

Tags: , , ,

Expression templates and meta-programming in boost::Spirit

March 25, 2007 at 5:31 PMAmer Gerzic

Introduction

According to one of expression templates inventors, Todd Veldhuizen, expression templates are “new C++ technique for passing expressions as functions arguments” [1]. The purpose of expression template is to inline expressions during compilation, which produces faster and arguably more readable code. Most of expression template articles focus on numeric array classes and operations on those using expression template techniques. For instance, expression templates could be utilized for matrix multiplication without using temporaries. For such article and code examples, please refer to articles referenced under [1] and [2].

As probably suspected, this article will not focus on expression templates as applied on numeric array classes. In this article, the focus will be on parsing and language recognition using expression template techniques. Furthermore the article will focus on Spirit library [3], a parser framework implemented completely using expression templates and template meta-programming. At this point the reader is encouraged to refer to introductory part of Spirit documentation as found here http://www.boost.org/libs/spirit/doc/introduction.html.

In addition it is important to note that this article will not focus on all parts of Spirit framework. This article is rather attempt to explain fundamentals behind expression templates as applied in Spirit framework.
More...

Posted in: CPP

Tags: , , , , , , ,

Enumerating System Devices on Windows

August 11, 2006 at 5:09 PMAmer Gerzic

Occasionally an application execution depends on installed devices. For example, USB memory card might be needed for storing/reading application specific files. But how do we know that such device is inserted/installed on the system?

Below is the code that enumerates all installed devices on a windows system.

HDEVINFO hInfoList = ::SetupDiGetClassDevs(NULL, NULL, NULL,
        DIGCF_PRESENT | DIGCF_ALLCLASSES | DIGCF_PROFILE);
if(hInfoList != INVALID_HANDLE_VALUE)
{
    SP_DEVINFO_DATA spdid;
    spdid.cbSize = sizeof(SP_DEVINFO_DATA); 

    DWORD dwIndex = 0;
    while(::SetupDiEnumDeviceInfo(hInfoList, dwIndex, &spdid))
    {
        CString strEntry = _T(""); 

        TCHAR szName[4096] = {0}; 

        if(::SetupDiGetClassDescription(&spdid.ClassGuid, 
                                        szName, 
                                        4096, 
                                        NULL))
        strEntry += szName;
        strEntry += " | "; 

        if(::SetupDiGetDeviceRegistryProperty(hInfoList, &spdid, SPDRP_DEVICEDESC, 0,
            (PBYTE)szName, 4096, 0))
        {
            strEntry += szName;
        }
        
        strEntry += " | "; 

        if(::SetupDiGetDeviceRegistryProperty(hInfoList, 
                &spdid, SPDRP_FRIENDLYNAME, 0, 
                (PBYTE)szName, 4096, 0))
        {
            strEntry += szName;
        } 

        m_DevList.AddString(strEntry); 

        ++dwIndex;
    }
} 

::SetupDiDestroyDeviceInfoList(hInfoList);

Posted in: CPP | Win32 API

Tags: , , , , ,