How add "version.txt" Version File by Command Line or by resources.res using dmd.exe
ShadoLight
ettienne.gilbert at gmail.com
Tue Dec 10 16:09:13 UTC 2019
On Tuesday, 10 December 2019 at 14:33:41 UTC, Marcone wrote:
> On Tuesday, 10 December 2019 at 09:48:11 UTC, ShadoLight wrote:
>> On Tuesday, 10 December 2019 at 07:23:00 UTC, rumbu wrote:
>>> [...]
>>
>> To add to Rumbo's comment: to compile a *.rc to *.res file you
>> will need a resource compiler.
>>
>> [...]
>
> Hi, I compile resource using windres.exe of MinGW, Can you send
> me the versionfile code mode to Dlang? Thank you.
I'm not a 100% sure what you mean, but note there isn't a
specific version "file format" (or something) that specifically
applies for "dlang apps only" - the format of a *.res applies to
all executables runnable on a specific platform (eg. EXEs, DLLs,
etc on Windows in this case).
You can use the same resource compiler to compile a *.rc to a
*.res file and link this with *.objs files produced in any native
language (C/C++/D/Pascal/etc) to create your EXE/DLL.
Here, for example, is a kind of minimalist *.rc file from an old
x86 app I did ages ago (edited to hide real names, etc):
////////////////////////////////////////////////////////
101 ICON DISCARDABLE ".\\Resources\\someicon.ico"
205 BITMAP DISCARDABLE ".\\Resources\\somebitmap.bmp"
STRINGTABLE DISCARDABLE
BEGIN
3001 "This string was loaded from the resource!"
END
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,0,1,2
PRODUCTVERSION 2,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "My Super Co\0"
VALUE "FileDescription", "Blah blah\0"
VALUE "FileVersion", "2, 0, 1, 2\0"
VALUE "InternalName", "MyApp\0"
VALUE "LegalCopyright", "Copyright (C) 2011\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "MyApp.exe\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "Blah blah\0"
VALUE "ProductVersion", "2, 0, 0, 1\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
////////////////////////////////////////////////////////
You can create the *.rc file by hand, but it is probably easier
just to use a freely available Resource editor. The above *.rc
file, IIRC, was created with XN Resource editor [1], but this was
long ago and nowadays I just typically use the one that is
bundled as part of Visual Studio.
Linking to a *.res file such as the one above will include the
resources directly in your EXE, and you then load the resources
during runtime using the listed "resource identifiers" (for
example 3001 for the string).
Regarding the version info - it will be automatically displayed
when you right-click the EXE (or DLL!) and select Properties. But
this is a feature of Windoxs, not your app. To display the
version info in your app (for example to display "My App
v1.0.0.2" instead of just "My App" in the Title-bar) you need to
do a little bit more work - you need to call the Windows API
GetFileVersionInfo function [2] to extract the version info. Look
at this [3] page for an example - it is in C but should be easy
to adapt.
[1] https://stefansundin.github.io/xn_resource_editor/
[2]
https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfoa?redirectedfrom=MSDN
[3]
https://stackoverflow.com/questions/940707/how-do-i-programmatically-get-the-version-of-a-dll-or-exe-file
More information about the Digitalmars-d-learn
mailing list