You’re on the right track, and your understanding of how windres
works is solid, but there’s a limitation you’re running into: Windows resource files (.rc
) don’t support placing a resource file at the “root” of .rsrc
without a type. Every resource embedded in a Windows executable must be associated with a resource type (like ICON
, MANIFEST
, or a numeric/custom type).
Why Your version.txt version.txt
Line Fails
In:
version.txt version.txt
You’re essentially saying: “Use the file version.txt
with no specified type or ID.” — and that’s not valid syntax for windres
. Every line needs a format like:
ID TYPE "filename"
What You Can Do Instead
You must assign a type to the resource. If you want to simulate a “root resource”, use a custom type and ID, like this:
1 MANIFEST "app.manifest"
1 ICON "app.ico"
1 "VERSION_TXT" "version.txt"
Or you can use a numeric type:
1 9999 "version.txt"
Here, 9999
is an arbitrary type ID. Then, when extracting or accessing it, you’d use that type.
There is no way to place a file at the root level of .rsrc
in the way Windows Explorer may show for Notepad.exe. That display is a side effect of the PE viewer interpreting certain resource types or system structures — it’s not something you can manually assign using .rc
syntax.
Recommendation
If your goal is to embed a version text for metadata, you might want to use a VERSIONINFO block, which is the standard for executable metadata. Example:
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x40004
FILETYPE 0x1
{
BLOCK "StringFileInfo"
{
BLOCK "040904b0"
{
VALUE "FileDescription", "My C++ App"
VALUE "FileVersion", "1.0.0.0"
VALUE "InternalName", "facts.exe"
VALUE "OriginalFilename", "facts.exe"
VALUE "ProductName", "My Product"
VALUE "ProductVersion", "1.0.0.0"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0409, 1200
}
}
This is what Notepad and most Windows apps use — and what you’re probably seeing in your third image.