5
votes

This is basically an extension of the question here.

I am working on an old MFC application where it seems the resource.h file has been manually edited and has gone messy. I see that there are conflicting IDs in there.

I just want to confirm if we can have two resources with the same ID of different type. For example, I have something like

IDD_1     101
IDS_2     101

or

IDR_1     102
IDS_2     102

Basically, there are resources defined with the same ID, but of different types.

A comment to the original question says that Resources of the same type don't share identifiers. If that is true, is it also valid for the IDR_xxxxIDs?

I am asking because I am using the Resource ID Organiser which seems to think that all IDs must be unique.

4

4 Answers

5
votes

Although it's not recommended it should work OK with different types. The API FindResource uses the ID and Type to identify the resource. The problems you're more likely to hit revolve around the way MFC uses the resource id to refer to another resource, e.g. the help text for a toolbar button. Those sort of bugs can be very time consuming so you might just want to bite the bullet now and re-number so your resource ids are unique.

2
votes

I am asking because I am using the Resource ID Organiser which seems to think that all IDs must be unique.

I thought I would just add that there is an option in Resource ID Organiser that allows for conflicts between symbol types:

ResOrg

It is not documented in the help topic.

0
votes

It depends on how the code uses the control. For example if the control is a button with a duplicate ID then there is no problem to use it. On the other hand, if the control is an entry of a menu then when the user click the related event finds the first available ID. I would think it is better to rearrange duplicate IDs.

0
votes

Sounds like you need a resource renumbering tool. Here's a free & open source one: https://sourceforge.net/projects/resrenum/

From the help file: "ResRenum renumbers resource IDs in Visual Studio C++ projects. It's a console app, and it's intended to be integrated into the IDE as an external tool. It's compatible with any version of Visual Studio from MFC 6.0 onwards. ... The resources are sorted in alphabetical order within each resource type. The resource types are sorted in compliance with Windows rules."

Note that this method only works if your resource IDs adhere to the Microsoft conventions, e.g. dialog IDs should start with IDD_ and so forth, see TN020 ID Naming and Numbering Conventions: https://msdn.microsoft.com/en-us/library/t2zechd4.aspx