Author Topic: How to add icon and version information to .exe?  (Read 35338 times)

Offline Sindarin

  • Single posting newcomer
  • *
  • Posts: 3
How to add icon and version information to .exe?
« on: September 04, 2009, 05:42:21 pm »
I am coding a Windows GUI Application in CB. I can compile my program perfectly. Problem is that I need to add a custom icon and version information in it.
As CodeBlocks has not a resource editor I had to do it myself. But it doesn't work. I checked numerous threads and the Code Blocks FAQ, but nothing solved my problems.

The files in my project root are main.cpp, resource.rc, icon.ico, theprogram.cbp, theprogram.layout

My program in main.cpp
Quote
#include <windows.h>
#include "resource.rc" //I indeed include resource.rc

...winmain, winproc etc.


resource.rc
Code
#include <windows.h> // include for version info constants

//ICON
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "icon.ico"

//VERSIONINFO

1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILETYPE VFT_APP
{
  BLOCK "StringFileInfo"
{
BLOCK "080904E4"
{
VALUE "CompanyName", ""
VALUE "FileVersion", ""
VALUE "FileDescription", "testing the description"
VALUE "InternalName", ""
VALUE "LegalCopyright", ""
VALUE "LegalTrademarks", ""
VALUE "OriginalFilename", ""
VALUE "ProductName", ""
VALUE "ProductVersion", ""
}
}
  BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0809, 1252
}
}

The Compiler stops in
C:\CPP Projects\theprogram\resource.rc|7|error: `A' does not name a type|
||=== Build finished: 1 errors, 0 warnings ===|

Any help? Thanks in advance.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: How to add icon and version information to .exe?
« Reply #1 on: September 04, 2009, 09:00:42 pm »
Code
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "icon.ico"
I don't think "A" is a valid keyword in a resource file. That's exactly what the resource compiler tells you. Icons are embedded completely different.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Sindarin

  • Single posting newcomer
  • *
  • Posts: 3
Re: How to add icon and version information to .exe?
« Reply #2 on: September 05, 2009, 09:32:51 pm »
Quote
I don't think "A" is a valid keyword in a resource file. That's exactly what the resource compiler tells you. Icons are embedded completely different.

I got the syntax from a resource file DevC++ created. I need to copy paste over the code to DevC++ to get my icon and version information correctly.

Anyone can provide a working example or resource creating and integration?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: How to add icon and version information to .exe?
« Reply #3 on: September 05, 2009, 09:35:04 pm »
Anyone can provide a working example or resource creating and integration?
Why don't you read yourself into resouce files if you want to use them? All information required is available, including examples from MSDN.

In the end: You should understand what you develop, right? What worth would be your software if you don't?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Sindarin

  • Single posting newcomer
  • *
  • Posts: 3
Re: How to add icon and version information to .exe?
« Reply #4 on: September 12, 2009, 02:44:07 pm »
Yes, but I could use some extra help, that's why I posted in this forum?

Nevertheless I found a solution, I'll leave it here in case someone else needs it.

In your main.cpp file add the line:
#include <winver.h>

Place your icon "myiconfilename.ico" file inside the project folder.

Create a new file in the project folder called resources.rc, and write into it

Code
#define VOS_NT_WINDOWS32    0x00040004L
#define VFT_APP                      0x00000001L

//this will set your .exe icon
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "myiconfilename.ico"

//include version information in .exe, modify these values to match your needs
1 VERSIONINFO
FILEVERSION 0,1,1,1
PRODUCTVERSION 0,1,1,1
FILETYPE VFT_APP
{
  BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "CompanyName", "write version info here"
VALUE "FileVersion", "write version info here"
VALUE "FileDescription", "write version info here"
VALUE "InternalName", "write version info here"
VALUE "LegalCopyright", "write version info here"
VALUE "LegalTrademarks", "write version info here"
VALUE "OriginalFilename", "write version info here"
VALUE "ProductName", "write version info here"
VALUE "ProductVersion", "write version info here"
}
}
  BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0409, 1252 //language codes
}
}

finally ADD the resources.rc and the icon in the CodeBlocks IDE by right clicking on the Management and selecting "Add Files..."
You're done!

Also if you want your controls (buttons, checkboxes etc.) to support modern Windows XP and Vista styles,
you must write a new file called "xp.manifest" and place it in the project folder as well, the file will contain an xml structure:

Code
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
  xmlns="urn:schemas-microsoft-com:asm.v1"
  manifestVersion="1.0">
<assemblyIdentity
    name="Exe.Apps.Project"
    processorArchitecture="x86"
    version="1.0.0.0"
    type="win32"/>
<description>Project</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="x86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>

Then update your resources.rc file with the line:
Code
1 24 "xp.manifest"

There you go. :)

I also suggest you update your F.A.Q. since it didn't provide enough info to solve my problem, let alone for other more inexperienced users.

sangmane

  • Guest
Re: How to add icon and version information to .exe?
« Reply #5 on: November 30, 2010, 06:34:15 am »
Hi Sindarin,

I was looking for how to add Version Info into dll. Your example works great!!!.

Thank you :)