" />

Duplicate Resource Finder for MFC Apps

  • Home
  • MFC
  • UI
  • Duplicate Resource Finder for MFC Apps

Developers have often faced with unexpected crashes in MFC applications when dealing with widgets (e.g. pressing a button or clicking on a menu). One of potential causes is a duplicate resource ID. If two resources have the same ID, the system gets confused while loading the UI element eventually leading to a crash or an unexpected behavior. This problem would not have existed if we use Visual Studio Resource editor to manage the resource ID allocation. But in practice, the resource file (resource.h and .rc files) is often subjected to manual tinker. The problem is little easier to resolve than it is to detect. First step is that if you suspect such problem in your application then peek into the resource header file for duplicate IDs. But this can easily end up in an experience of “finding a needle in the haystack” even for a medium sized application (about 50 to 60 UI items). There will be hundreds of IDs. You would need to load the file in a smart text editor, fire complex regex search queries and fix the duplicates. Even with all this, you can never be too sure. 

During my first few days as a developer, my approach was a little raw. I did this..

1.   Load the resource header in an intelligent text editor like Notepad++.

2.   Remove other parts of the header which are not definitions.

3.   Detect and remove any End of Line and delimiter character mix-up such as combined use of tab & space to separate the definition statements, New Line Characters mix-up, etc. Even this step can solve the problem.

4.   Replace the delimiter with comma and save the file as .csv.

5.   Load it in any spreadsheet application which load .csv and sort the name and ID column.

6.   Use a formula to detect two consecutive lines of a column having same value. I’m not so good at this so I had used a simple script for that.

Painful, isn’t it? Now, if you have multiple projects with many modules, resource DLLs, imported resources, multiple developers across
different geographies and time zones then you are in whole lot of trouble. 
Eventually, I ended up in developing a utility application which automates this for me. Loads the resource files and identifies the duplicate IDs.

Here is a screenshot of it.

Fig1: Illustration of the Developed Application-Duplicate Resource ID Finder

This application detects duplicates in names as well as IDs too. This can detect duplicates from multiple files too. All this just at a click of a button! Unbelievable, isn’t it? I would love to share this application for free with you,

Contact us : info@prototechsolutions.com

Author : Pavan S.

 

 

Tags:

About

ProtoTech Solutions is a custom engineering software development company with skills in 3D visualization on desktop/mobile/cloud. My role in the company is essentially Business Development and Marketing.

View all posts by

POST A COMMENT

You must be logged in to post a comment.