4

I tried to add custom icons (13x13 dimention) to a project.

I cannot find why I cannot load icon.

CVTRES : fatal error CVT1100: duplicate resource. type:ICON, name:1, language:0x0409 LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

Some information from resource.h:

#define IDI_LOGO   16   //0x10 - no problem here
...
/* Bitmaps */
#define IDB_LOGO            200
#define IDB_GOOD            201
#define IDB_EVIL            202

/* Icons */
#define IDI_TERRAIN 90 // problem starts here
#define IDI_ELEV    91
#define IDI_DRAWREPLACE 92
#define IDI_DRAWFILL    93
#define IDI_DRAWBRUSH   94

common.rc:

#include "resource.h"
/* Bitmaps */ // no problem
#define IDB_LOGO            200
#define IDB_GOOD            201
#define IDB_EVIL            202

/* Icons */ // problem:
#define IDI_TERRAIN 90
#define IDI_ELEV    91
#define IDI_DRAWREPLACE 92
#define IDI_DRAWFILL    93
#define IDI_DRAWBRUSH   94

file2.rc:

#include "resource.h"
IDI_LOGO    ICON    DISCARDABLE "res/swgbts.ico"






#include "resource.h"
IDI_LOGO    ICON    DISCARDABLE "res/aokts.ico"

I tried to change the id of the IDI_TERRAIN and other icons, did not help.

According this: https://msdn.microsoft.com/en-us/library/b1kw34cb%28v=vs.80%29.aspx I tried to change the number, did not help

Note that if I comment out the problematic lines, IDI_LOGO is loaded. Any help?

The error is in resource.h Visual Studio C++ 2010, Windows XP

Siav Josep
  • 130
  • 2
  • 10
John Boe
  • 3,501
  • 10
  • 37
  • 71

4 Answers4

5

I ran into the same issue. Looks like it is impossible to merge .rc. files if they both have icons. Despite the non-overlapping numbering scheme you might have.

See below explanation from Microsoft: Gary Chang has posted this interesting explanation elsewhere on the net:

The following is more detail info on the root cause of this problem: "Basically what's happening is that Icon resources are composed of two different Win32 resource types C RT_GROUP_ICON and RT_ICON. You can think of RT_GROUP_ICON as a directory of RT_ICON resources. The RT_ICON resources are the actual icon images.

The VC resource editor tries to simplify this for you in a single icon resource entity and under the hood handles some things like creation and ID naming of the individual RT_ICON resources (the #1 you're seeing in this case). The VC resource editor was also created back in the day when it was only possible to have a single .rc file in a given .exe or .dll. Changes have since been made in the command line tools to allow use of multiple .rc files to contribute to a given .exe or .dll but I don't believe the resource editor implementation was ever revisited with this new possibility in mind, at least from the standpoint of the way it handles icons.

So with the current VC++ compiler,the only thing that can be done in this case if you want to have multiple resource files is to keep all icon (and cursor) resources in a single .rc file. That will let the VC resource editor keep all the RT_ICON identifiers unique."

Wish this helps and thanks for your understanding! Best regards,

Gary Chang Microsoft Community Support

E. van Putten
  • 615
  • 7
  • 17
  • I now store the icons as raw `RCDATA` in the resource files that are "included" by the "main" project. Now `CVTRES` can merge the compiled resource files just fine. I also have included dialog resources but unlike icons `CVTRES` is fine with that. The hard part is to obtain `HICON`. For this I have to call `CreateIconFromResourceEx` with the bits obtained from `LookupIconIdFromDirectoryEx`. And before that, the pointer to the raw ICO file bytes (from the resource) has to be obtained via functions `FindResource`, `LoadResource`, `LockResource`, `VirtualProtect` etc. – E. van Putten Jul 10 '18 at 13:04
  • 1
    The funnies thing here is this quote from _Gary Chang_, from the link above: > _So with current VC resource compiler, I am afraid there is no way to do this, **but our product team members will fix it in the future.**_ It was said exactly 14 (fourteen) years ago. But the absolutely same problem still exist in 2019. – Jovibor Aug 14 '19 at 10:07
  • Even funnier is that nobody (that includes me) has filed a bug report. So I just did. – E. van Putten Aug 14 '19 at 11:15
  • Stay in touch for any news related) – Jovibor Aug 15 '19 at 00:37
  • 1
    There was already a ticket for that:https://developercommunity.visualstudio.com/content/problem/363156/visual-studio-2017-prof-1557-cvt1100-duplicate-res.html And https://social.msdn.microsoft.com/Forums/vstudio/en-US/ca805bad-9893-483b-8482-6e6ccaa0a4f8/cvtres-fatal-error-cvt1100-duplicate-resource-typeicon-name1-language0x0409-link-?forum=vclanguage – E. van Putten Aug 16 '19 at 08:08
  • The problem is more in the linker then in the rc compiler. Multiple .rc files create multiple .res files. If you merge these .res files first with a tool and then add the .res file to the vc project instead of the individual .rc files the problem is solved. Unfortunately I have not yet made these tools public. – Arnoud Mulder Jan 29 '20 at 23:02
  • @ArnoudMulder, it is never too late to publish it on Github. Come to think about it, I have converted my icons to source code, in a similar way as what the `xxd -i` tool does, that see here: https://stackoverflow.com/questions/8707183/script-tool-to-convert-file-to-c-c-source-code-array – E. van Putten Jan 30 '20 at 08:36
3

I Solved the problem.

I have moved content of one .rc file to main rc file. The compiler had problem to include ICONs from two resources. I have no idea why but this is clear and simple solution.

John Boe
  • 3,501
  • 10
  • 37
  • 71
1

For me, it just has duplicated resource IDs.

#define IDB_LOGO            200
...
#define IDB_EVIL            200

Changing one of them would resolve the problem.

Zhang
  • 3,030
  • 2
  • 14
  • 31
0

I had this problem in VC 2015 but at small changes error

2>CVTRES : fatal error CVT1100: duplicate resource. type:DIALOG, name:564, language:0x041B 2>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

I'm having any *.rc files in *.vcxproj and my resource.h is:

#define IDC_1  100
#define IDR_1  101
//etc
//about 
#define IDXXX_XXX  12000
//and
#define ID_1 32769
//etc

I replaced defines from 100 to 999 after "IDXXX_XXX" renumber and rebuild. So problem is solved.

John Conde
  • 217,595
  • 99
  • 455
  • 496