Do I need afxres.h, if I am not using MFC? How do I remove it from the .RC script?
Asked Answered
C

3

10

I don't know RC scripts.

I want to include Product version, File version, etc. metadata into a DLL I'm building. I'm using an .rc file to do that. The build is makefile driven. I'm following along with an example .rc scrpit I found.

The template .rc file includes afxres.h , but I don't think I need that. But if I just remove it I get a bunch of compile errors.

What does a basic, non-MFC RC script look like? Can I remove all the stuff like this:

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

....
Cnut answered 15/10, 2009 at 22:51 Comment(0)
C
3

My answer:
NO, I don't need all that crap. Here's an RC script that works for VERSIONINFO.

#define VER_FILEVERSION          1,2,3,4
#define VER_FILEVERSION_STR      "1.2.3.4"
#define VER_PRODUCTVERSION       1,2,0,0
#define VER_PRODUCTVERSION_STR   "1.2.0.0"

// -------------------------------------------------------

VS_VERSION_INFO VERSIONINFO
 FILEVERSION            VER_FILEVERSION
 PRODUCTVERSION         VER_PRODUCTVERSION
 FILEFLAGSMASK 0x17L
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
    BLOCK "040904b0"
    BEGIN
    VALUE "CompanyName",      "Company X"
    VALUE "FileDescription",  "Description Goes Here"
    VALUE "InternalName",     "NotSure"
    VALUE "LegalCopyright",   "Copyright (C) 2009 Your Name Here"
    VALUE "OriginalFilename", "DllName.dll"
    VALUE "ProductName",      "Product Title"
    VALUE "FileVersion",      VER_FILEVERSION_STR
    VALUE "ProductVersion",   VER_PRODUCTVERSION_STR
    END
END
BLOCK "VarFileInfo"
BEGIN
    VALUE "Translation", 0x409, 1200
END
END

Conmpile it with:

$(WindowsSDK)\bin\RC.exe /FoProjectName.res ProjectName.rc
Cnut answered 15/10, 2009 at 23:9 Comment(1)
You can edit the resource file all you like. The advantage of leaving the lines you delete alone is to be able to edit it automatically using the resource editor. If you look closely, you will see that the second reference to afxres.h rebuilds the first one when the file is regenerated. Therefore replace both references to afxres.h with windows.h (since you are not using MFC) and the problem will be solved.Helmer
S
10

I had a similar problem when trying to compile without MFC. The solution of Cheeso would not work adequately for me.

Everything compiled okay, and I saw no errors/warnings during building. The Icon which was defined in my resource file was shown correctly in 'windows explorer'. However, the version data was not available. (Which can be seen when right-clicking on the executable and selection properties. In this case there was no 'version' tab present.)

To get it working I had to add the following include at the top of the .rc file:

#include <windows.h>

With this change, the version tab would show up in the properties of the executable. Also, the .NET System.Diagnostics.FileVersionInfo class is now able to get the version information, while this would not work before.

Defaultly "stdafx.h" would include "windows.h". I'm not sure why windows.h is required, but it seems to make the difference in my case.

Edit: Added some more specific information, in response to Cheeso.

Shoreward answered 26/4, 2010 at 8:36 Comment(2)
Are you saying the rc.exe failed to compile the rc script, without that included file? What symbol was not defined? How did it fail?Cnut
This should be the accepted answer, working like charm. thanks!Thermos
C
3

My answer:
NO, I don't need all that crap. Here's an RC script that works for VERSIONINFO.

#define VER_FILEVERSION          1,2,3,4
#define VER_FILEVERSION_STR      "1.2.3.4"
#define VER_PRODUCTVERSION       1,2,0,0
#define VER_PRODUCTVERSION_STR   "1.2.0.0"

// -------------------------------------------------------

VS_VERSION_INFO VERSIONINFO
 FILEVERSION            VER_FILEVERSION
 PRODUCTVERSION         VER_PRODUCTVERSION
 FILEFLAGSMASK 0x17L
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
    BLOCK "040904b0"
    BEGIN
    VALUE "CompanyName",      "Company X"
    VALUE "FileDescription",  "Description Goes Here"
    VALUE "InternalName",     "NotSure"
    VALUE "LegalCopyright",   "Copyright (C) 2009 Your Name Here"
    VALUE "OriginalFilename", "DllName.dll"
    VALUE "ProductName",      "Product Title"
    VALUE "FileVersion",      VER_FILEVERSION_STR
    VALUE "ProductVersion",   VER_PRODUCTVERSION_STR
    END
END
BLOCK "VarFileInfo"
BEGIN
    VALUE "Translation", 0x409, 1200
END
END

Conmpile it with:

$(WindowsSDK)\bin\RC.exe /FoProjectName.res ProjectName.rc
Cnut answered 15/10, 2009 at 23:9 Comment(1)
You can edit the resource file all you like. The advantage of leaving the lines you delete alone is to be able to edit it automatically using the resource editor. If you look closely, you will see that the second reference to afxres.h rebuilds the first one when the file is regenerated. Therefore replace both references to afxres.h with windows.h (since you are not using MFC) and the problem will be solved.Helmer
D
3

I got the same error when upgrading the RBTray project in VS2019.

After changing afxres.h to winres.h (as in the VS2019 WinApp example project .rc file), the compilation succeeded.

Desman answered 30/8, 2021 at 10:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.