CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2019
    Posts
    15

    [RESOLVED] Visual C++ 2019 afxres.rc not including afxres.h for some reason

    I have some C++ MFC projects - sample code - that compile as-is under 2013 but fail to compile as-is under 2019. The errors (RC2104) are all about undefined constants, that are defined in afxres.h, and then used to build STRINGTABLEs in afxres.rc. afxres.h is in the default install location in the include folder.

    All I did was a default install of VS 2019, added MFC to it (prompted to add at first run), and then tried to build one of the projects. I think it is pretty vanilla. Also I reimaged Windows on this desktop a couple of days ago so it is a pretty clean Windows environment.

    I tried doing an explicit #include in afxres.rc but that didn't work. I was able to hack it and get it to build by copying the entire contents of afxres.h into afxres.rc. With this single change, it builds and runs as expected.

    My question is, how do I fix this without hacking into the afxres files?

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    Does afxres.rc have an #include "afxres.h" statement somewhere near the top?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Oct 2019
    Posts
    15

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    Yes, it is the first line. It has a qualifier that I commented out. However it looks like the entire rc file only gets used if __AFXRES_RC__ is not defined. It looks like the #endif for that first #ifndef statement is at the end of the whole file. Not sure why it is set up like that? Maybe that is the problem?

    Code:
    // This is a part of the Microsoft Foundation Classes C++ library.
    // Copyright (C) Microsoft Corporation
    // All rights reserved.
    //
    // This source code is only intended as a supplement to the
    // Microsoft Foundation Classes Reference and related
    // electronic documentation provided with the library.
    // See these sources for detailed information regarding the
    // Microsoft Foundation Classes product.
    
    #ifndef __AFXRES_RC__
    #define __AFXRES_RC__
    
    // #ifndef __AFXRES_H__
    	#include <afxres.h>
    // #endif
    
    
    ... (down to end of file)
    
    #endif // _AFX_INTL_RESOURCES
    
    #endif //!_AFXDLL
    #endif //!__AFXRES_RC__
    
    /////////////////////////////////////////////////////////////////////////////

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    __AFXRES_RC__ is the header guard to prevent errors from multiple compilation if the file is included more than once in a compilation unit. Modern include files often use #pragma once at the beginning instead which accomplishes the same result more easily.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Oct 2019
    Posts
    15

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    Quote Originally Posted by 2kaud View Post
    __AFXRES_RC__ is the header guard to prevent errors from multiple compilation if the file is included more than once in a compilation unit. Modern include files often use #pragma once at the beginning instead which accomplishes the same result more easily.
    OK thanks so that is not the problem. I did try removing the copied definitions and commenting out the header guard in both the .rc and the .h file and get the same error. So it does not seem to be a problem of some other definition out there.

    So it looks like it is just not finding the .h file. It is included and it seems to be in the right directory but the build currently only succeeds if I copy the .h contents into the .rc

    Here is what the include folder looks like:

    Name:  mfc-dir.jpg
Views: 11248
Size:  28.9 KB
    Last edited by bigteks; October 11th, 2019 at 11:03 AM. Reason: Added screen shot

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    If the compiler can't find the .h file, then you will get fatal error C1083 and the compilation will stop.

    There isn't multiple versions of afxres.h in different locations are there - with the compiler using the 'wrong version'?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Oct 2019
    Posts
    15

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    I will search for that

  8. #8
    Join Date
    Oct 2019
    Posts
    15

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    Quote Originally Posted by 2kaud View Post
    If the compiler can't find the .h file, then you will get fatal error C1083 and the compilation will stop.

    There isn't multiple versions of afxres.h in different locations are there - with the compiler using the 'wrong version'?
    Yes you are correct, there is. The sample code has its own copy of afxres.h that leaves out all the definitions. How do I handle that? It only has a few lines as follows, the "real" afxres.h has probably 100 definitions:

    Code:
    #ifndef _AFXRES_H
    #define _AFXRES_H
    #if __GNUC__ >= 3
    #pragma GCC system_header
    #endif
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    #ifndef _WINDOWS_H
    #include <windows.h>
    #endif
    
    	/* IDC_STATIC is documented in winuser.h, but not defined. */
    #ifndef IDC_STATIC
    #define IDC_STATIC (-1)
    #endif
    
    #ifdef __cplusplus
    }
    #endif
    #endif

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    Try renaming the 'wrong one'.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #10
    Join Date
    Oct 2019
    Posts
    15

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    I would probably need to disable the "guard" code in the wrong one as well, correct?

  11. #11
    Join Date
    Oct 2019
    Posts
    15

    Re: Visual C++ 2019 afxres.rc not including afxres.h for some reason

    Quote Originally Posted by bigteks View Post
    I would probably need to disable the "guard" code in the wrong one as well, correct?
    This did it. By renaming the "extra" copy of the file and disabling the header guard in the file, it now builds without changing the official files.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured