Source files not recompiled when resource header file changed
-
Monday, September 17, 2012 3:08 AMI am developing an application with MS Visual C++ 2008 Express. Because the Express edition does not include a resource editor, I edit the resource file and the header file containing the #define statements for its resource identifiers and control identifiers as text files.I inadvertently gave the same numeric value to two different control identifiers in the same dialog. I'm surprised that the resource compiler didn't warn me about this error but that's not the issue here.
I discovered what I had done when I was trying to figure out why
EnableWindow(GetDlgItem(hDlg, ID_BUTTON), TRUE)
did not enable the pushbutton that it should have. (It was enabling the other control with the same control ID.)
I changed the value of the button's identifier in the header file and rebuilt the project. The rebuild compiled the resource file but nothing else! The dialog procedure which included the resource header file and used the control ID which I had change was not recompiled so it still failed to enable the pushbutton as I expected it to. I had to change the code (by inserting and deleting a space character) before I could get the file recompiled.My questions are:- Why is the resource header file treated differently from other header files? It is listed along with all of the other header files as a member of the project. And the code file has the same sort of #include statement for it as it does for the other header files.- And, more importantly, how can I get this header file to be treated as my other header files are, so that changes trigger recompilation of all of the code files which use it?Thanks,NormNorm
All Replies
-
Monday, September 17, 2012 4:30 AM- Why is the resource header file treated differently from other header files? It is listed along with all of the other header files as a member of the project. And the code file has the same sort of #include statement for it as it does for the other header files.
Show the list of #include statements in the source (code) file
which has this resource header #include - preserve the exact
order used for the build.
Do you have precompiled headers enabled for this project?
- Wayne
-
Monday, September 17, 2012 11:28 AM
I am developing an application with MS Visual C++ 2008 Express. Because the Express edition does not include a resource editor, I edit the resource file and the header file containing the #define statements for its resource identifiers and control identifiers as text files.
I know that in an MFC project, every .cpp file by default includes resource.h, so changing resource.h alone is prevented from causing recompilation (otherwise the whole project would recompile).
I am surprised if this happens in a non-MFC project, but perhaps that is what you are seeing.
David Wilkinson | Visual C++ MVP- Marked As Answer by Elegentin XieMicrosoft Contingent Staff, Moderator Tuesday, September 25, 2012 10:37 AM
-
Monday, September 17, 2012 1:46 PM
Thanks for that hint.
Do you think that changing the name of "resource.h" to something else will solve the problem?
Norm
Norm
-
Monday, September 17, 2012 2:19 PM
-
Wednesday, September 19, 2012 1:51 AM
I tried it.
First I renamed "resource.h" to "resources.h" using the menu from right-clicking on the file name in the list of headers in the solution. Then I edited all of the #include statements (including the one in the .rc file) that had "resource.h". Finally I rebuilt the solution so that all of the .obj files would be up to date with the changed source files.
Next I edited the resources.h file, just changing the order of some of the #define statements so that the resource IDs were separated from the control IDs. When I pressed F7 to rebuild, only the .rc file was recompiled.
Thinking that perhaps I needed to change a value, I changed the numeric value of one of the resource ID. Rebuild only compiled the .rc file. Next I changed the value of a control ID. Again rebuild only compiled the .rc file.
Then I thought that perhaps it was identifying this "magic" header that doesn't cause files to be recompiled by the appearance of its name in the .rc file: the line that tells the resource editor (if you have one) where to put the #define statements for resource IDs. I changed that line but rebuild still compiled only the .rc file.
One last possibility: perhaps the "magic" header is flagged in the solution properties or the properties of the file itself so I deleted the file from the solution and then added it back in using the "Add Existing Item" menu. The rebuild still compiled only the .rc file.
Can't think of anything else to try.
Norm
Norm
-
Wednesday, September 19, 2012 11:39 AM
I tried it.
Did you see this link
http://blogs.msdn.com/b/vcblog/archive/2011/04/05/10149742.aspx
?
David Wilkinson | Visual C++ MVP -
Thursday, September 20, 2012 2:17 AM
Seems a little strange that I should be reading a blog that tells how to make VC++2010 work like VC++2008 did when I am running VC++2008 and I don't want it to work the way it does.
One of the issues mentioned is that VC++2010 disregards the "//{{NO_DEPENDENCIES}}" in the resource.h file. I don't think VC++2008 uses this line either; I think it was one of the lines that I deleted yesterday when I separated the resource IDs from the control IDs. In any case, that line is not in my header file.
If my General Properties sheet had a "No dependencies file list" attribute I would remove resource.h from it but I don't have that attribute.
What I'm looking for is a way to ensure that VC++2008 recompiles every source file that includes "resource.h" whenever resource.h is changed.
Norm
-
Thursday, September 20, 2012 2:32 AM
What I'm looking for is a way to ensure that VC++2008 recompiles every source file that includes "resource.h" whenever resource.h is changed.
How big is this project? How much time have you spent
trying to find a way to make this work?
It seems to me it would be far simpler and take far less
of your time if you were simply to do a Rebuild instead
of a Build every time you make a change to the resource
files.
- Wayne
- Marked As Answer by Elegentin XieMicrosoft Contingent Staff, Moderator Tuesday, September 25, 2012 10:37 AM

